Search code examples
djangodjango-urls

Trying to get Django to load the server without using the paths I created. The default path is not working


my urls.py will not allow Django to run the server.

The error message visual studio code gives when I hover over the red squiggly line that visual studio gives over the URL patterns [ is: "[" was not closed.

Can anyone explain to me what that error message means and how to solve it?

Also, I am trying to get my Django server to run the server on its own. But it will not open the main page. It was able to run the other paths when I put the URL after the /'finance' or /'ingredients' respectively but that was before the bug popped up. I am certain the error is tied to preventing Django to load the server.

urls.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!')

enter image description here

What have I tried to do to solve the problem? I have tried looking at stack overflow examples. I have tried reaching out on the Django discord. I have tried researching the error message on the internet. I have tried looking at a Django course on an udemy equivalent.


Solution

  • I see that you already fixed the issue with unclosed [].

    It seems that the path for the root "/" is missing in the urls declaration. You need to explicitly tell django which view you want to run in that path. Look this example:

    urlpatterns = [
        path(
            '',
            TemplateView.as_view(template_name='template/index.html'),
            name='index',
        ),
    ]