[Django]-How to get Django url correctly?

3๐Ÿ‘

โœ…

I would suggest doing whatever you can to get your prod and dev as identical as possible, however if thats not possible you could use separate urlpatterns for the development environment.

Assuming you have a settings.DEBUG set, try the following:

extra_patterns = patterns('',
    (r'enroll/$', 'enroll'),
)

if settings.DEBUG:
    urlpatterns = patterns('', (r'^', include(extra_patterns)))
else:
    urlpatterns = patterns('', (r'^activity/', include(extra_patterns)))
๐Ÿ‘คRobert Clark

3๐Ÿ‘

django.core.urlresolvers.reverse() or {% url %} can be used to turn a view reference or named urlconf into a URL suitable for output.

Leave a comment