Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django URL resolving infrastructure stops working

We recently launched a new Django-powered website, and we are experiencing the oddest bug:

The site is running under Apache with mod_fastcgi. Everything works fine for a while, and then the URL tag and reverse() functionality stops working. Instead of returning the expected URL, they return "".

We haven't noticed anything in Apache's log file; there are no errors being generated by Django. And (the kicker) the problem only occurs in production mode; we can't reproduce it when DEBUG=True.

Any thoughts on where we should be looking for the problem?

Update: It turned out to be a problem with settings.LANGUAGES, although we haven't determined exactly why that broke things.

like image 706
Brian Tol Avatar asked Feb 19 '26 22:02

Brian Tol


2 Answers

This has happened to me before. Normally it's due to a 'broken' urls.py file. There are two things that make this kind of bug really hard to fix:

  • It could be the urls.py file in any of the apps that breaks the reverse() function, so knowing that reverse() breaks for app X doesn't mean the error is in that particular application's urls.py.
  • Django won't even notify you of errors in the urls.py file, unless you somehow manage to crash the site by doing something really, really nasty in the urls.py file.

Debugging: The way I go around fixing this is by manually disabling all applications (just comment out their line in INSTALLED_APPS) and checking reverse() works. If it still works, then I enable the next app, until it breaks. I know, very rudimentary stuff, but it works :)

like image 62
dguaraglia Avatar answered Feb 21 '26 14:02

dguaraglia


Django has a odd behaviour when matching urls in a environment that isn't under debug mode.

For example, with DEBUG=False, Django will ignore urls such as:

url(r'^', include('someapp.urls')),

specifically in the case above, you could let the string empty:

url(r'', include('someapp.urls')),

In other words, check your regexes.

Can you put your urls.py here to be analyzed?

like image 31
Gabriel Falcão Avatar answered Feb 21 '26 14:02

Gabriel Falcão



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!