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

Difference between static STATIC_URL and STATIC_ROOT on Django

STATIC_ROOT The absolute path to the directory where ./manage.py collectstatic will collect static files for deployment. Example: STATIC_ROOT=”/var/www/example.com/static/” now the command ./manage.py collectstatic will copy all the static files(ie in static folder in your apps, static files in all paths) to the directory /var/www/example.com/static/. now you only need to serve this directory on apache or … Read more

Django – after login, redirect user to his custom page –> mysite.com/username

A simpler approach relies on redirection from the page LOGIN_REDIRECT_URL. The key thing to realize is that the user information is automatically included in the request. Suppose: LOGIN_REDIRECT_URL = ‘/profiles/home’ and you have configured a urlpattern: (r’^profiles/home’, home), Then, all you need to write for the view home() is: from django.http import HttpResponseRedirect from django.urls … Read more

Django optional url parameters

There are several approaches. One is to use a non-capturing group in the regex: (?:/(?P<title>[a-zA-Z]+)/)? Making a Regex Django URL Token Optional Another, easier to follow way is to have multiple rules that matches your needs, all pointing to the same view. urlpatterns = patterns(”, url(r’^project_config/$’, views.foo), url(r’^project_config/(?P<product>\w+)/$’, views.foo), url(r’^project_config/(?P<product>\w+)/(?P<project_id>\w+)/$’, views.foo), ) Keep in mind … Read more