我的 urls.py 将不允许 Django 运行服务器。
当我将鼠标悬停在 Visual Studio 在 URL 模式 [ 上给出的红色波浪线上时,Visual Studio 代码给出的错误消息是:“[”未关闭。
任何人都可以向我解释该错误消息的含义以及如何解决它吗?
另外,我正在尝试让我的 Django 服务器独立运行。但它不会打开主页。当我将 URL 分别放在 /'finance' 或 /'ingredients' 之后时,它能够运行其他路径,但那是在错误弹出之前。我确信该错误与阻止 Django 加载服务器有关。
url.py
from django.contrib import admin
from django.urls import include, path
from django.http import HttpResponse
urlpatterns = [ # <----- error is on this thing
path('admin/',name ='inventory' admin.site.urls),
path('finance/', finance, name='finance'),
path('home/', home, name='home'), #I am attempting to connect the home_view function with the views function.
path('ingredients/', ingredients, name='ingredients'),
path('menu/', menu, name='menu'),
path('purchases/', purchases, name='purchases'),]
views.py
def finance(request):
return HttpResponse('Here are our business results')
def home(request):
return HttpResponse
def ingredients(request):
return HttpResponse('Here is the ingredients page')
def menu(request):
return HttpResponse('Here is the menu page!')
def purchases(request):
return HttpResponse('Here is where you can find the order history!')
我尝试过做什么来解决这个问题? 我尝试查看堆栈溢出示例。 我尝试过解决 Django 的不和谐问题。 我尝试在互联网上研究错误消息。 我尝试过查看 udemy 上的 Django 课程。
我看到您已经解决了未关闭的问题
[]
。
url 声明中似乎缺少根“/”的路径。 您需要明确告诉 django 您要在该路径中运行哪个视图。 看这个例子:
urlpatterns = [
path(
'',
TemplateView.as_view(template_name='template/index.html'),
name='index',
),
]