Home > front end >  django is not responding urls.py file
django is not responding urls.py file

Time:02-02

I am writing basic views and then putting it in urls.py but it is still not working.

views.py
[from django.shortcuts import render
from django.http import HttpResponse

def home(request):
    return HttpResponse("hello how are you")

project urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
        path('admin/', admin.site.urls),
        path('',include('blog.urls')),
     ]

apps urls.py
from django.urls import path
from . import views
urlpatterns = [
        path('home/',views.home,name='home')
    ]

I have also included my app in settings of project (Installed apps).

CodePudding user response:

Some thoughts about that:

Change your urls patterns in your apps urls to:

from .views import *
urlpatterns= [
    path('', home,name='home')
]

If its not working send us your installed apps settings and wsgi file

CodePudding user response:

You confused, you need to write http://127.0.0.1:8000/home not only http://127.0.0.1:8000 with your current code.

If you want the view to be rendered in default route so change urls.py as:

from . import views

urlpatterns= [
    path('', views.home,name='home')
]

Otherwise, you can only append /home with your current code to work.

  • Related