简体   繁体   中英

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. TO import food.url.py i used include method to import food.url.py in mysite.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')

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

you does not require to add from mysite import food

just add path('', include('food.urls') where food.urls in single quotation

Make sure food app added in your INSTALLED_APPS list in settings.py

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:

 path('',include('food.urls'))

just add one single quotes..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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