I have the following setup:
FrontEnd folder views.py
:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home_page(request):
return HttpResponse("New App")
FrontEndfolder urls.py
:
from django.urls import path
from . import views
urlpatterns = [
path('home/', views.home_page, name='home_page'),
]
Main Project folder urls.py
:
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('', include('FrontEnd .urls')),
path("admin/", admin.site.urls),
]
However I can’t open http://localhost:8000.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Heya,
The error you’re encountering is because Django is unable to find a URL pattern that matches the root path (i.e., http://127.0.0.1:8000/
). In your ``Project folder urls.py
, you’ve included the URLs from your FrontEnd folder urls.py
under the path ''
, which means it’s expecting additional path information to match the defined URL patterns.
In your FrontEnd folder urls.py
, you’ve defined a URL pattern home/
, which means the view home_page
in your app will respond to http://127.0.0.1:8000/home/
, but there’s no URL pattern defined for the root path http://127.0.0.1:8000/
.
To resolve this, you can define a URL pattern in your project’s urls.py
for the root path. For example:
from django.urls import path, include
from FrontEnd.views import home_page
urlpatterns = [
path('', FrontEnd.home_page, name='home_page'),
path('FrontEnd/', include('FrontEnd.urls')),
path("admin/", admin.site.urls),
]
This will make the home_page
view respond to http://127.0.0.1:8000/
.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.