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.
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'),
]
When I go to this URL http://127.0.0.1:8000/job/all I am always receiving a 404 error with this message:
404 Django Error screenshot
However, when I just go to http://127.0.0.1:8000/ or http://127.0.0.1:8000 it always finds the / (index) route correctly regardless if there is a trailing slash, or not. This issue seems to only happen with the /job/WHATEVER_ELSE_GOES_HERE URLs.
I have the following URLs setup:
My jobs app urls.py:
from django.urls import path
from .views import *
urlpatterns = [
path('', index, name="index"),
path('job/<int:job_id>', job_details, name="job_detail"),
path('job/all/', all_jobs, name="all_jobs"),
path('job/add/', add_job, name="add_job"),
path('job/my_posted_jobs/', my_posted_jobs, name="my_posted_jobs"),
path('job/delete/<int:job_id>', delete_job, name="delete_job"),
path('job/search', search_job, name="search_job"),
path('job/apply_for_job/<int:job_id>', apply_for_job, name="apply_for_job")
]
My project's urls.py:
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('jobs.urls')),
path('user/', include('users.urls')),
path('payments/', include('payments.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
In the error message (screenshot) it also says this:
The current path, job/all, matched the last one.
How come it matches a URL but returns 404?
How do I fix it?
Thank you
You have to include the "/" since you have included it in your syntax in your urls.py therefore call the url from your web browser using the link below when you have started the Django web server.
http://127.0.0.1:8000/job/all/
I'm just beginning to learn Django.
I've created a simple web sub-app called 'flavo' inside of another one called 'djangoTest'
When I run http://127.0.0.1:8000/flavo
it correctly displays
Hello, World!
then when I run http://127.0.0.1:8000/flavo/a it should show
Hello, a!
But instead I get:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/flavo/a
Using the URLconf defined in testDjango.urls, Django tried these URL patterns, in this order:
admin/
flavo [name='index0']
flavo a [name='a']
The current path, flavo/a, didn’t match any of these.
in testDjango/hello/views.py I have
from django.http import HttpResponse
from django.shortcuts import render
def index0(request):
return HttpResponse("Hello, world!")
def a(request):
return HttpResponse("Hello, a!")
In testDjango/flavo/url/py I have
from django.urls import path
from . import views
urlpatterns = [
path("", views.index0, name="index0"),
path("a", views.a, name="a"),
]
The only other file I've changed is , testDjango/testDjango/urls.py"
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('flavo', include("flavo.urls")),
]
I'm confused why I can't access http://127.0.0.1:8000/flavo/a
Add '/'.
like this.
# testDjango/testDjango/urls.py
path('flavo/', include("flavo.urls"))
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),
I have a problem with Django. Actually I want to create a login panel in my new site but when I try to write address the debugger respond me a error:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/account/login
Using the URLconf defined in firmowa.urls, Django tried these URL patterns, in this order:
admin/
^account/
The current path, account/login, didn't match any of these.
My firmowa.urls is
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path(r'^account/', include('account.urls')),
]
And the project urls.py is:
from django.urls import path
from . import views
urlpatterns = [
path(r'^login/$', views.user_login, name='login'),
]
I'm looking a solution from few hours but still nothing.
path is a new feature in Django 2.0 and works different than the old url. Don't use regex in path. If you need regex, use re_path instead, but in your case there's no need for that.
Change your code to:
urlpatterns = [
path('login/', views.user_login, name='login'),
]
etc. and it should work.
More on the topic here and here.
from django.urls import path
from . import views
from django.conf.urls import url
urlpatterns = [
url( r'^$', views.index , name='index') ,
]