Home > front end >  configure urls in django, cmd prints: AttributeError: module 'myapp.views' has no attribut
configure urls in django, cmd prints: AttributeError: module 'myapp.views' has no attribut

Time:05-31

i have been trying to run this code but it doesn't show the Hey, Welcome inthe views.py

myproject/myapp/views.py

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("<h1>Hey, Welcome</h1>")

myproject/myapp/urls.py

urlpatterns=[
path(" ",views.index, name="index")

]



myproject/urls.py
urlpatterns = [
path('admin/', admin.site.urls),<br>
path(' ', include('myapp.urls') ),

]




pls can you help me figure out what im doing wrong, when i run the code, it only shows 'the install worked successfully! congratulation!!' without run the html code that i pass inthe views.py

CodePudding user response:

Please remove space from the url pattern.

myproject/myapp/urls.py

urlpatterns=[
    path("",views.index, name="index")
]

myproject/urls.py

urlpatterns=[
    path("",views.index, name="index")
    path('', include('myapp.urls') )
]

CodePudding user response:

You are using space in path which result in this mess Try removing those spaces

path("",views.index, name="index")
path('', include('myapp.urls')),

refer this for more clarity Spaces in URLs?

  • Related