简体   繁体   English

urls.py中的Django错误

[英]Django error in urls.py

I have a problem trying to setup django project: 我在尝试设置Django项目时遇到问题:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',


url(r'^admin/', include(webshop.admin.site.urls)),
url(r'^about/', include(webshop.views.about)),
url(r'^products/', include(webshop.views.available_products)),
url(r'^products/(\d+)/', include(webshop.views.productview)),

and I get the next error: 我得到下一个错误:

Exception Type: NameError
Exception Value:    
name 'webshop' is not defined
Exception Location: /home/Python/myProject/myProject/urls.py in <module>, line 11

UPDATE: Thanks, it was nub, mistake. 更新:谢谢,这是个小错误。

Now, I'm getting this error: 现在,我收到此错误:

Exception Value: 异常值:
No module named about 没有名为的模块

Thanks for help, it my first time using django 感谢您的帮助,这是我第一次使用Django

将包含的网址文件路径用引号引起来:

url(r'^admin/', include('webshop.admin.site.urls')),

NameError shows up when you've not defined a name -- any name that you're trying to evaluate. 当您尚未定义名称(您要评估的任何名称)时,就会显示NameError。

From the docs : 从文档

Raised when a local or global name is not found. 在找不到本地或全局名称时引发。 This applies only to unqualified names. 这仅适用于不合格的名称。 The associated value is an error message that includes the name that could not be found. 关联的值是一条错误消息,其中包含找不到的名称。

So this code would cause NameError to be thrown at the second line assigning to a : 所以这个代码会导致NameError在第二行分配给抛出a

def foo():
    a = 1
    b = 2
    a = c + (a * b)

In order to fix your problem, you should probably add an import webshop to your code before you reference it use quoted strings, as in this example in the django docs . 为了解决您的问题,您可能应该 在代码中添加一个 import webshop ,然后再 使用带引号的字符串 引用它 ,如django docs中的此示例所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM