Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the root url in Django

In my view, I want to make a request to mine.com/more/stuff/ from an arbitrary page such as mine.com/lots/of/stuff/to/use or from mine.com. Thus, I can't make this a relative request using ./ or ./../ type things. Do I have to use a context processor to do {{URL_BASE}}more/stuff/? Is there a set way to do this in Django or a best way?

like image 585
Alexis Avatar asked Jan 17 '26 04:01

Alexis


1 Answers

why don't you use named urls? it's always works. for example {% url 'admin:index' %} always printed as url to admin(in case if you using default django.contrib.admin app). if you'll have in urls.py smth like

url(r'^lots/', Lots.as_view(), name='lots'),

then just use smth like

{% url 'lots' %}

Don't hardcode your urls!

like image 156
MechanisM Avatar answered Jan 19 '26 20:01

MechanisM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!