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:
- Create a python module for
urls
(just as you would do for the settings) - Inside that dir, create your
base_urls.py
,local_urls.py
andproduction_urls.py
- Inside the
base_urls
you should put the “global” urls that’ll be available for both local and production. Inside thelocal_urls
put any additional local urls (likedjango-debug-toolbar
). And finally, in your production put… eh the production urls. Of course,local_urls.py
andproduction_urls.py
files should havefrom .base_urls import *
at the top. - After that, you should change the
ROOT_URL_CONF
setting inside thesettings/local.py
file to be"project.urls.local_urls"
and inside thesettings/production.py
file change (again) theROOT_URL_CONF
setting to"project.urls.production_urls"
.
Now, you have separate urls
files, for each environment.
👤nik_m
Source:stackexchange.com