I am starting work on a mature Django project and notice something unusual. When I edit urls.py -- whether at the project level or below -- Django ignores my changes.
Debugging is on, so when I get a 404 Django prints all the URL patterns it tried. From this I see the URL patterns from before I made my changes.
Again, this is regardless of whether I edit /project/urls.py or /project/sub/urls.py. To be sure, the subdirectory urls.py is being included correctly.
I am focusing on the project level urls.py, just in case.
I can make a small update to urls.py or delete all of its contents. The 404 debug info shows the old url patterns.
It is as if Django is looking at a cached version of these urls.py files. How should I proceed?
Set up app folder's urls.py and html files In the same directory, you should have a file named views.py. We will create a function called index which is what makes the http request for our website to be loaded. Now, we've set it up such that http://127.0.0.1:8000/homepage will render the HTML template index.
Django provides tools for performing URL reversing that match the different layers where URLs are needed: In templates: Using the url template tag. In Python code: Using the reverse() function. In higher level code related to handling of URLs of Django model instances: The get_absolute_url() method.
This tells Django to search for URL patterns in the file books/urls.py . For example, A URL request to /books/crime/ will match with the second URL pattern. As a result, Django will call the function views.
In Django 2.0, you use the path() method with path converters to capture URL parameters. path() always matches the complete path, so path('account/login/') is equivalent to url('^account/login/$') . The part in angle brackets ( <int:post_id> ) captures a URL parameter that is passed to a view.
By deafult, Django's development server (accessed via the runserver
management command) will keep an eye on your code and reload itself whenever something changes. If you are using any other server (including Django's testserver
command) this is almost certainly not the case.
Typically, a server will load the source of your application when it starts. It will need to be reloaded to get the latest copy of your code. If you are using Apache with mod_wsgi (probably the most common production server for Django applications), somewhere in your source tree you will have a wsgi application file. By convention these have a .wsgi
extension, but it can be named anything. This file is what Apache uses to load your source and a useful feature of mod_wsgi (daemon mode only) is that touching (changing the modification date) this file is enough to force the server to erload the source code. If your application has a wsgi file you can edit, doing so and re-uploading the code should be enough. The file is likely to contain the line application = django.core.handlers.wsgi.WSGIHandler()
or something like it - this may help you
If you do not have access or you cannot find any such file, you will need to give the updated source to the server's administrator and ask them to update and reload the source. It's tricky to give you more advice without more information - perhaps you could ask the server administrator for more information so we can be mroe helpful?
== Update ==
I've checked the response headers on the link you've provided and it looks like you are using nginx to serve the site. This may just be a load-balancer in front of another server though, so I'd still recommend asking for more info from your SysAdmin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With