0

这是问题所在:

在 Django views.py 之一中,我有以下代码:

from kml_generator import KML_generator

@login_required(login_url='/dev/login')
def search(request):

    if request.POST:
        result,SF=Validate(request, Activities)
        val=result.values('id')        
        KML_generator(result1=val,user=request.user)   

它基本上导入模块并从那里kml_generator调用类。KML_generator此类生成.kml文件,然后显示在 OpenLayers 上。它可以正常工作,但我想改变它。

现在:

为什么当我更改模块内的代码时kml_generator它不会影响行为?我尝试了所有我什至放在那里的错误,它仍然像魅力一样工作......

那么问题来了:

如何改变它?django 内部是否有某种“构建”、“编译”?我需要调用它来影响代码吗?

PS。这一切都在使用 wsgi.py 的 Apache 上

PS2。好吧,这对我来说很可悲,但我们有一家公司为我们开发了一个不错的动态 django 网站。现在我不知道为什么它不能像我一样工作。

4

1 回答 1

4

You need to restart the Apache server for Django to pick up changes.

Python loads source files just once, when a module is imported. The compiled bytecode is then kept in memory. At import time, Python also caches the bytecode, in a .pyc file next to the original source file, you can verify that a new import has taken place by comparing timestamps on the .py and corresponding .pyc files.

A graceful restart should suffice; run apache2ctl graceful as root on your server.

In future, you may want to get yourself a development setup; running the same code (from a VCS, of course), but using the built-in Django development server:

python manage.py runserver

The Django development server does its best to reload code when you change it. This is a development feature only (watching files for changes costs performance).

Last but not least, try to avoid altering third-party libraries. Use subclassing or monkeypatching instead, and perhaps the upstream author would be willing to implement new features for you or accept patches. That way you don't have to maintain those changes yourself across versions either.

于 2013-10-15T09:39:57.523 回答