Django忽略对/project/urls.py的更改 [英] Changes to /project/urls.py ignored by Django

查看:92
本文介绍了Django忽略对/project/urls.py的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个成熟的Django项目,并注意到一些不寻常的事情。当我编辑urls.py - 无论是在项目级别还是在下面 - Django忽略我的更改。



调试已经开启,所以当我获得一个404 Django打印所有它尝试的URL模式。从此我在我进行更改之前,先查看中的URL模式



同样,这是无论是否编辑/项目/网址。 py或/project/sub/urls.py。可以肯定的是,子目录urls.py正确包含在内。



我专注于项目级别urls.py,以防万一。



我可以对urls.py进行一个小的更新或删除其所有内容。 404调试信息显示旧的url模式。



就像Django正在查看这些urls.py文件的缓存版本一样。如何继续?

解决方案

通过deafult,Django的开发服务器(通过 runserver 管理命令)会随时关注您的代码,并在任何更改时自动重新加载。如果您使用任何其他服务器(包括Django的 testserver 命令),这几乎肯定不是这样。



服务器启动时将加载应用程序的源代码。需要重新加载才能获取最新的代码副本。如果您使用Apache与mod_wsgi(可能是Django应用程序最常见的生产服务器),您的源代码树中的某个位置将具有一个wsgi应用程序文件。按照惯例,这些都有一个 .wsgi 扩展名,但它可以命名任何东西。这个文件是Apache用来加载你的源代码,mod_wsgi(仅限守护程序模式)的一个有用功能是触摸(更改修改日期),这个文件足以强制服务器去掉源代码。如果您的应用程序有一个wsgi文件,您可以编辑,这样做,并重新上传代码就足够了。该文件可能包含行 application = django.core.handlers.wsgi.WSGIHandler()或类似的东西 - 这可能会帮助您



如果您没有访问权限,或者找不到任何此类文件,则需要将更新的源文件提供给服务器的管理员,并要求他们更新并重新加载源代码。在没有更多信息的情况下给你更多的建议是棘手的 - 也许你可以向服务器管理员询问更多信息,以便我们可以帮助你吗?



==更新==

我已经检查了您提供的链接上的响应标头,并且您似乎正在使用nginx来提供该网站。这可能只是另一个服务器前面的负载平衡器,所以我仍然建议您从SysAdmin中询问更多信息。


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?

解决方案

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.

这篇关于Django忽略对/project/urls.py的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆