[英]can anyone help me, why I am getting food is not defined error ? I have attached the structure of Django module
I have added food app.我添加了食物应用程序。 inside food app i added url.py.
在食品应用程序中,我添加了 url.py。 TO import food.url.py i used include method to import food.url.py in mysite.url.py.
要导入 food.url.py,我使用了包括在 mysite.url.py 中导入 food.url.py 的方法。 but while running the server i am getting error as food is not defined
但是在运行服务器时我收到错误,因为食物没有定义
Pass argument in strings of include function like need not be import your apps在包含函数的字符串中传递参数,例如不需要导入您的应用程序
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('food.urls')), #change in this line
]
In this URLs pattern pass argument in include method as string like include ('food.urls')在此 URL 模式中,将 include 方法中的参数作为字符串传递,如 include ('food.urls')
In this file not need the import a food apps but see the your import statment syntax is wrong if you use this way python interpreter will find __init__.py
file in module so create please refer documention of python module or see the following enter link description here在此文件中不需要导入食品应用程序,但如果您使用这种方式,请查看您的导入语句语法错误 python 解释器将在模块中找到
__init__.py
文件,因此创建请参阅 python 模块的文档或在此处查看以下输入链接描述
you does not require to add from mysite import food
您不需要添加
from mysite import food
just add path('', include('food.urls')
where food.urls
in single quotation只需在单引号中添加
path('', include('food.urls')
where food.urls
Make sure food
app added in your INSTALLED_APPS list in settings.py
确保将
food
应用添加到settings.py
INSTALLED_APPS列表中
In above file first of all you don't need to add from mysite import food And in your url_patterns the second urls is giving like this:首先在上面的文件中,您不需要添加from mysite import food并且在您的 url_patterns 中,第二个网址是这样的:
path('',include('food.urls'))
just add one single quotes..只需添加一个单引号..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.