18π
β
I think the proper way here is use the {% url %}
tag and Iβm assuming that you have a root url in your url conf.
urls.py
url(r'^mah_root/$', 'someapp.views.mah_view', name='mah_view'),
Then in your template:
<a href="{% url mah_view %}">Go back home</a>
π€Henrik Andersson
15π
You should be able to access the get_host() method of the request:
<a href="http://{{ request.get_host() }}">Go back home</a>
Though you could probably also do:
<a href="/">Go back home</a>
- Django Nested Groups: Groups in Groups
- Testing a custom Django template filter
- Django GROUP BY field value
9π
I found a trick, Use this tag:
{{ HTTP_HOST }}
you could do:
<a href="{{ HTTP_HOST }}"> back home <a>
or
<a href="{{ HTTP_HOST }}/what_you_want"> back home <a>
π€Charlie Lutaud
- Render an xml to a view
- Get a list of python packages used by a Django Project
- Updating context data in FormView form_valid method?
2π
this is what i did:
in urls.py:
from django.contrib import admin
from django.urls import include, path
from django.views.generic import TemplateView
urlpatterns = [
path('blog/', include('blog.urls')),
path('admin/', admin.site.urls),
path('', TemplateView.as_view(template_name='landing.html'), name='landing')
]
then, in whatever view:
<a href="{% url 'landing' %}">Site Title</a>
this will resolve to localhost:8000/ or site.domain.com/ whichever you are using, when you click the link
π€p4ndepravity
- Sometimes request.session.session_key is None
- What is query.clone(), queryset.clone() for in django?
- Django test: TransactionManagementError: You can't execute queries until the end of the 'atomic' block
- Soft deleting objects in django
- Issues with queryset and slicing
1π
Referring to standard Django example:
urlpatterns = [
path('', views.index, name='index'),
]
Then template code:
href="{% url 'index' %}"
will also work.
π€TPRLab
- Where are the files downloaded using pip stored in virtualenv?
- Django. Error message for login form
- Issues with queryset and slicing
- SAML with Django authentication
Source:stackexchange.com