'Why is my Python Django home url not working?
my first url in django is not working. Not sure what I am doing. My directories are as follows:
Storefront
- playground
- urls.py
- views.py
- storefront
- urls.py
playground.urls
from nturl2path import url2pathname
from django.urls import path
from . import views
urlpatterns = [
path('hello/', views.hello)
]
playground.views
from django.shortcuts import render
from django.http import HttpResponse
def hello(request):
return HttpResponse('Hello World')
storefront.urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('playground/', include('playground.urls'))
]
When I go to the website/playground/url, I get an error saying the urls wasn't found. What am I doing wrong?
Solution 1:[1]
Edit: Sorry I realized what I wrote before was incorrect because I answered it in a rush.
I used the exact code you put in the question and was unable to reproduce the error.
Make sure you are going to the following web address:
127.0.0.1:8000/playground/hello
The reason this is the address is because in storefront.urls you are specifying that the root of the storefront app is the "playground/" route and the only route in the playground app is "hello/".
If you want to go to the following and have it show the "hello" view like this:
127.0.0.1:8000/playground/
You will need to change:
path('hello/', views.hello)
to this instead:
path('', views.hello)
If you are looking for a good tutorial on Django, Codemy.com has a free playlist on YouTube. John goes through step by step to build a full blog website. Here is the link: https://www.youtube.com/playlist?list=PLCC34OHNcOtr025c1kHSPrnP18YPB-NFi
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
