[Fixed]-Urlpatterns and Django Debug Toolbar

1đź‘Ť

âś…

There’s nothing wrong with this approach since you’ll only have one URL conf file that will live inside your project root. So the if settings.DEBUG: part, inside your project’s root urls.py file looks fine with me.

However, if you want to completely seperate the local and production urls, then you could do it this way:

  1. Create a python module for urls (just as you would do for the settings)
  2. Inside that dir, create your base_urls.py, local_urls.py and production_urls.py
  3. Inside the base_urls you should put the “global” urls that’ll be available for both local and production. Inside the local_urls put any additional local urls (like django-debug-toolbar). And finally, in your production put… eh the production urls. Of course, local_urls.py and production_urls.py files should have from .base_urls import * at the top.
  4. After that, you should change the ROOT_URL_CONF setting inside the settings/local.py file to be "project.urls.local_urls" and inside the settings/production.py file change (again) the ROOT_URL_CONF setting to "project.urls.production_urls".

Now, you have separate urls files, for each environment.

👤nik_m

Leave a comment