Home > OS >  why at django framework vscode extension pylance giving me reed line at path
why at django framework vscode extension pylance giving me reed line at path

Time:11-19

If I write the following code:

from django.contrib import admin
from django.urls import path
from home import views

urlpatterns = [
    path("/", views.home, name='home')
    path("about", views.about, name='about')
    path("services", views.services, name='services')
    path("about", views.contact, name='contact')
]

VS Code marks the second path function with a red line.

what can be the problem here?

CodePudding user response:

This is your code:-

from django.contrib import admin
from django.urls import path
from home import views

urlpatterns = [
   path("/", views.home, name='home')
   path("about", views.about, name='about'),
   path("services", views.services, name='services')
   path("about", views.contact, name='contact')

]

Your problem is you need to add (coma)" , " after all path function. A and You need to change Your last path "about/" to "contact/" .

This is right:-

from django.contrib import admin
from django.urls import path
from home import views

urlpatterns = [
   path("/", views.home, name='home')
   path("about/", views.about, name='about'),
   path("services/", views.services, name='services')
   path("contact/", views.contact, name='contact')

]

CodePudding user response:

The code you wrote is incorrect: you are working with a list, and you should use commas between the different paths, so:

from django.contrib import admin
from django.urls import path
from home import views

urlpatterns = [
    path("/", views.home, name='home'),  # ← comma
    path("about", views.about, name='about'),  # ← comma
    path("services", views.services, name='services'),  # ← comma
    path("about", views.contact, name='contact')
]

other problems are that you do not use a slash at the end (this is not mandatory, but is advisable). Finally two of your paths have the same name, so likely the one with about should be contact:

from django.contrib import admin
from django.urls import path
from home import views

urlpatterns = [
    path("/", views.home, name='home'),
    path("about/", views.about, name='about'),
    path("services/", views.services, name='services'),
    path("contact/", views.contact, name='contact')
]
  • Related