How to get URL of current page, including parameters, in a template?

Write a custom context processor. e.g. def get_current_path(request): return { ‘current_path’: request.get_full_path() } add a path to that function in your TEMPLATE_CONTEXT_PROCESSORS settings variable, and use it in your template like so: {{ current_path }} If you want to have the full request object in every request, you can use the built-in django.core.context_processors.request context processor, … Read more

How to get the current url name using Django?

I don’t know how long this feature has been part of Django but as the following article shows, it can be achieved as follows in the view: from django.core.urlresolvers import resolve current_url = resolve(request.path_info).url_name If you need that in every template, writing a template request can be appropriate. Edit: APPLYING NEW DJANGO UPDATE Following the … Read more

Django URL Redirect

You can try the Class Based View called RedirectView from django.views.generic.base import RedirectView urlpatterns = patterns(”, url(r’^$’, ‘macmonster.views.home’), #url(r’^macmon_home$’, ‘macmonster.views.home’), url(r’^macmon_output/$’, ‘macmonster.views.output’), url(r’^macmon_about/$’, ‘macmonster.views.about’), url(r’^.*$’, RedirectView.as_view(url=”<url_to_home_view>”, permanent=False), name=”index”) ) Notice how as url in the <url_to_home_view> you need to actually specify the url. permanent=False will return HTTP 302, while permanent=True will return HTTP 301. Alternatively … Read more

How can I list urlpatterns (endpoints) on Django?

If you want a list of all the urls in your project, first you need to install django-extensions You can simply install using command. pip install django-extensions For more information related to package goto django-extensions After that, add django_extensions in INSTALLED_APPS in your settings.py file like this: INSTALLED_APPS = ( … ‘django_extensions’, … ) urls.py … Read more

Django multi tenancy

For ease of use, Django packages as compiled a page full of every possible existing django package that can accomplish this. However below is my own simple implementation I modified my nginx proxy config to use the following server_name ~(?<short_url>\w+)\.domainurl\.com$; … stuff related to static files here location / { proxy_set_header X-CustomUrl $short_url; …. other … Read more

Django : How can I see a list of urlpatterns?

If you want a list of all the urls in your project, first you need to install django-extensions You can simply install using command. pip install django-extensions For more information related to package goto django-extensions After that, add django_extensions in INSTALLED_APPS in your settings.py file like this: INSTALLED_APPS = ( … ‘django_extensions’, … ) urls.py … Read more