I have searched endlessly for a solution and I can't seem to find it, even though I know this has been asked before. I am encountering a perpetual 404 error from the django tutorial. It appears to me that the 'urlpatterns' isn't recognizing another option of than admin.
backend/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('test/', include('meat.urls')),
path('admin/', include(admin.site.urls)),
]
backend/meat/urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
backend/meat/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(requests):
return HttpResponse('Hello Wold')
In order to access views inside the meat app.
you have included the urls of meat to the test/ path.
Thus you should use url /test/
if you are developing on local host then localhost:8000/test/
NB: I have tested this right now link
PS: try changing the path of admin site to path('admin/', admin.site.urls),
Related
I am following the django tutorial (found here):
views.py code:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
urls.py code (this is inside polls app urls.py file):
from django.urls import path, include
from django.conf import settings
from . import views
urlpatterns = [path(r'^$', views.index, name='index'), ]
urls.py code ( this is root urls.py file code):
from django.contrib import admin
from django.urls import include, path
urlpatterns = [path('polls/', include('polls.urls')),path('admin/',admin.site.urls), ]
Here is my run command : python manage.py runserver 8080
I tried to run it today, but I am getting the following error:
Page not found (404)
Request Method: GET
Request URL: http://35527a91f40c4e228d6c464d8a8c8487.vfs.cloud9.eu-west-1.amazonaws.com/
Using the URLconf defined in PollApp.urls, Django tried these URL patterns, in this order:
poll/
admin/
The empty path didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
You are using regex-syntax with path, you should use the empty string instead:
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Furthermore, you use a poll/ prefix here, so that means you either need to visit localhost:8000/poll/, or change this to an empty prefix:
urlpatterns = [
path('', include('polls.urls')),
path('admin/', admin.site.urls),
]
Djano errors are self-explanatory, follow its instructions, and are good to go.Also is there the Indentation in your first return ?
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
I am a total beginner in "django" so I'm following some tutorials currently I' am watching https://youtu.be/JT80XhYJdBw Clever Programmer's tutorial which he follows django tutorial
Everything was cool until making a polls url
Code of views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
HttpResponse("Hello World.You're at the polls index")
Code of polls\urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Code of Mypr\urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/',admin.site.urls),
path('polls/',include('polls.urls')),
]
I don't get it I did the same thing but I'm getting error not only polls.In one turtorial he decided to make blog,and again the same error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/
Using the URLconf defined in Mypr.urls, Django tried these URL patterns, in
this order:
admin/
The current path, polls/, didn't match any of these.
Please my seniors help me.
Note:I'm using the latest versions of django,windows and as editor I'm using Pycharm.
Already tried(and did not work):
from django.urls import path
from polls.views import index
urlpatterns = [
path('', index, name='index'),
]
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/
Using the URLconf defined in Mypr.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file.
Change that to False, and Django will display a standard 404 page.
try to access polls/ URL in your browser then you will access the page
Because you have accessed the URL of your project, you have to go to this URL to access your app
try by changing your code like this
from django.urls import path
from polls.views import index
urlpatterns = [
path('', index, name='index'),
]
I was facing the same error. Feel kinda dumb after figuring out how to solve this.
Your urls.py content is all right
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
But it must be included in the mysite\mysite\urls.py and not in mysite\urls.py.
That means the inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it.
I'm very new to working with Django and I've been relying on some tutorials to link this one to React, but the problem is that initially (when I open 127.0.0.1:8000) React loads the routes perfectly, then when I reload the page Django tries to interpret the path from urls.py and obviously can't find it.
The error is:
Page not found (404) Using the URLconf defined in memberstack.urls, Django tried these URL patterns, in this order:
admin/
api/token-auth/
core/
I hope you can help me, thanks in advance
my_project/urls.py
from django.contrib import admin
from django.urls import path, include
from rest_framework_jwt.views import obtain_jwt_token
from frontend.views import index
urlpatterns = [
path('', include('frontend.urls')),
path('admin/', admin.site.urls),
path('api/token-auth/', obtain_jwt_token),
path('core/', include('core.urls')),
]
frontend/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
]
frontend/views.py
from django.shortcuts import render
def index(request):
return render(request, 'frontend/index.html')
For this, you'll have to use a catch-all in order for React to handle all the routing instead of django there.
from django.urls import path, re_path
from . import views
urlpatterns = [
path('', include('frontend.urls')),
path('admin/', admin.site.urls),
path('api/token-auth/', obtain_jwt_token),
path('core/', include('core.urls')),
re_path(r'^(?:.*)/?$', include('frontend.urls')),
]
Or
urlpatterns = [
path('', views.index),
re_path(r'^(?:.*)/?$', views.index)
]
I think the better practice would be to implement Django-Rest-Framework and build them separately.
I am doing a Django course and in my first tutorial only I am getting "Page on found 404 error" while mapping the URL will the view.
I referred to this link and did same steps I am still getting same error.
https://docs.djangoproject.com/en/3.0/intro/tutorial01/
polls/urls.py
-------------
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
polls/view.py
-------------
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
mysite/urls.py
--------------
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
Directory of my code
Help me with the error... I checked all sources and followed exactly the link... Still cannot run it properly
after wasting saturdays eve googling for a solution to finally make a Django server work, i need your assistance..
I first of all want to set up my project in that way that http://127.0.0.1:8000/ redirects me to the index.html site. But somehow I am not able to run the Django server within my virtualenv (access denied).
I handled error over error in the past few hours (inserted a Secret key, inserted silenced_system_checks since E408/09/10 occured as errors before the current error) and here I stuck now. I am not capable to understand the prompt error at all. I assume that Django wants to start the server but can't find a file/html to return?
urls.py // dassocc_app dir
from django.urls import path
from django.urls import include
from django.conf.urls import url
from . import views
urlpatterns = [
path('/dasocc_site/dasocc_app/templates/', include("dasocc_app.views")),
path('', views.liga, name="index"),
]
views.py
import requests
from django.shortcuts import render
def liga(request):
liga = ['1. Bundesliga', 'Premier League', 'La liga']
return render(request, 'dasocc_app/templates/index.html', {'liga': liga})
urls.py // dasocc_site dir
from django.urls import path
from django.urls import include
from dassoc_app import views
urlpatterns = [
url(r'^$', views.liga, name='index')
]
enter image description here
Your troublemaker is the line path('', views.index, name="index"). It cannot find a function called index in your views.py.
Assuming the function you want to call is liga() you will have to write
path('', views.liga, name="index").
Or you could rename your liga function to index
#2
Kindly change your dassoc_site.urls:
dassoc_site/urls.py
from dasocc_app import views
from django.conf.urls import url, include
urlpatterns = [
url(r'^$', views.liga, name='index'),
url(r'^dassoc-app/', include('dassoc_app.urls')),
]
dassoc-app/urls.py
from django.conf.urls import url
from dasocc_app import views
urlpatterns = [
# Where home is some random view from your dassocc-app
url(r'^$', views.home, name='home')
]