page not found : / Django - python

I'm new to Django and I want to add new url but I got this error:
Watching for file changes with StatReloader
System check identified no issues (0 silenced).
July 14, 2020 - 20:19:51
Django version 2.2.2, using settings 'cineam.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /
here is my url.py:
from django.contrib import admin
from django.urls import path, include
from ticketing import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('ticketing/', include(urls))
]
ticketing/urls.py :
from django.urls import path
from ticketing.views import cinema_list
urlpatterns=[
path('movies/list/', cinema_list),
]
can anybody help me?

You haven't mentioned which URL you were trying to access.I assume you were trying to access localhost:8000 or http://127.0.0.1:8000/. in this case you will get this error "Page NOT FOUND."
Try this and then try accessing the same URL again, It will work
from django.contrib import admin
from django.urls import path, include
from ticketing import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("ticketing.urls"))
]
else if you were accessing localhost:8000/ticketing/ it will still bring the error because
you have not pointed which urls.py file you are trying to access. In that case...
from django.contrib import admin
from django.urls import path, include
from ticketing import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('ticketing/', include("ticketing.urls"))
]

Related

Django - The current path, job/all, matched the last one. - But it still returns 404

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/

Page not found at /polls

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.

Django Tutorial Constant 404 error urlpattern recognition

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),

How to make virtualenv Django server work? // 'missing attribute' according to command prompt

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')
]

Module Not FoundError Python Django

I am trying to map the base URL to my "Learning Logs's" home page. here is the following code I have in my main urls.py file:
from django.contrib import admin
from django.urls import path
from django.urls import include
urlpatterns = [
path('admin/', admin.site.urls),
path(r' ', include('learning_logs.urls', namespace='learning_logs')),
]
I save the file and look at the terminal to see if there are any issues and it spits out the following error: ModuleNotFoundError: No module named 'learning_logs.urls'
I am no to python/django and following a book called the python crash course. not sure what I am doing wrong please help!
Best solution is check author's updates:
http://ehmatthes.github.io/pcc/chapter_18/README.html#updates
updates for urls.py
from django.urls import path, include
from django.contrib import admin
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('learning_logs.urls')),
]
Updates for learning_logs/urls.py
"""Defines url patterns for learning_logs."""
from django.urls import path
from . import views
app_name = 'learning_logs'
urlpatterns = [
# Home page.
path('', views.index, name='index'),
]

Categories

Resources