只是一个又快又脏的回答。在
Import对于python来说是非常重要的语句,而include仅限于django,对于django至关重要。Import用于导入python模块,而include在django中用于为应用程序提供模块化。在A function that takes a full Python import path to another URLconf
module that should be “included” in this place. Optionally, the
application namespace and instance namespace where the entries will be
included into can also be specifiedTo use any package in your code, you must first make it accessible.
You have to import it. You can't use anything in Python before it is
defined. Some things are built in, for example the basic types (like
int, float, etc) can be used whenever you want. But most things you
will want to do will need a little more than that.
更新:
URLconf是一个文件(通常称为网址.py)它包含给定特定应用程序的所有url模式映射。在您的示例Polls中,Polls是一个将URLconf文件另存为的应用程序网址.py(放在polls文件夹中)。现在要将请求发送到您的应用程序url(比如http://example.com/polls/stats),dango需要包含您的urlconf,这是通过include语句实现的。你可以写下polls.url在主管道内网址.py并完成删除url(r'^polls/', include('polls.urls')),
不推荐这样做,因为它看起来很难看,增加了代码的重复性,而且以后删除应用程序会变得一团糟。在