Am using django I got this error Page not Found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in VibezT.urls, Django tried these URL patterns, in this order
music/
admin/
The empty path didn't match any of these.
VibezT\urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns =[
path('music/', include('music.urls')),
path('admin/', admin.site.urls),
]
For music URLs I have this code
music\urls.py
from django.urls import path
from . import views
urlpattern = [
path(r'^$',/ views.index, name='index')
]
For views i have this code
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World")
You have not defined a URL for / in your code. Your code is defined for music/
You need to go to http://127.0.0.1:8000/music/ to find your view.
Also, I do not know why you are structuring your URL like this if you are using path. path(r'^$',/ views.index, name='index')
Just replace that with this:
path('', views.index, name='index'),
in your music\urls.py
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 was taking a youtube tutorial on making a basic website using django and I got this error when coding:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
app/
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.
This is my code:
For urls.py/mysite:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('app/', include('myapp.urls')),
path('admin/', admin.site.urls),
]
For views.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world!")
For urls.py/myapp:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
You need to add root level path to access the path you specified http://127.0.0.1:8000/:
urls.py/mysite
urlpatterns = [
path('', views.index, name='home'),
path('app/', include('myapp.urls')),
path('admin/', admin.site.urls),
]
views.py/mysite
def index(request):
return HttpResponse('This is home page')
Since you specified:
path('app/', include('myapp.urls')),
It means all the paths in myapp.urls are prefixed with app/. So you can access the index view with: http://127.0.0.1:8000/app/. Or if you want to access the index view with http://127.0.0.1:8000/ you rewrite the path to:
path('', include('myapp.urls')),
I got the follwoing error whenever I run the project and automatically catalog/ is added to the url:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/catalog/
Using the URLconf defined in first_project.urls, Django tried these URL patterns, in this order:
[name='index']
admin/
first_app/
The current path, catalog/, 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.
Here is my project urls.py
from django.contrib import admin
from django.urls import path, include
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
path('first_app/', include('first_app.urls')),
]
Here is first_app urls.py code:
from django.urls import path
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
]
How to get the index page as a default and get rid of the catalog.
Here is views.py file:
from django.shortcuts import render
from django.http import HttpResponse
from first_app.models import Topic, AccessRecord, Webpage
# Create your views here.
def index(request):
webpages_list = AccessRecord.objects.order_by('date')
date_dict = {'access_records': webpages_list}
return render(request, 'first_app/index.html', context=date_dict)
Hey Mak in your code u didnt mention any url related to /catalog/ so you are getting that 404 error message. Error 404 means that the page couldnt found by the server add /catalog/ in your url patterns so that the server could know which page is to be shown if /catalog/ is requested . And as far as ur proble"and automatically catalog/ is added to the url:" may be its your browser autocompleting the address field so once plesase check it. if the request is only /catalog then ur myproject urls.py file should be something like this
from django.contrib import admin
from django.urls import path, include
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
path('first_app/', include('first_app.urls')),
path('catalog',views.your_function_name)
]
if the request is first_app/catalog then ur first_app urls.py file should be something like this in url patterns
urlpatterns = [
path('/catalog', views.catalog, name='catalog'),
]
from django.contrib import admin
from django.urls import path, include
from first_app import views
urlpatterns = [
path('admin/', admin.site.urls),
path('first_app/', include('first_app.urls')),]
and
from django.urls import path
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
]
>>>>> if your templates files :
templates/index.html
def index(request):
webpages_list = AccessRecord.objects.order_by('date')
date_dict = {'access_records': webpages_list}
return render(request, 'index.html', context=date_dict)
I keep getting this error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/home
Using the URLconf defined in personal_portfolio.urls, Django tried these URL patterns, in this order:
admin/
home/
The current path, home, didn't match any of these.
This is my urls.py for the overall project
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('home/', include('hello_world.urls')),
]
this is my code for hello_world urls.py
from django.urls import path
from hello_world import views
urlpatterns = [
path('home/', views.hello_world, name='hello_world'),
]
this is my code for hello_world views.py
from django.shortcuts import render
def hello_world(request):
return render(request, 'hello_world.html')
you need to change this url from
urlpatterns = [
path('home/', views.hello_world, name='hello_world'),
]
to
urlpatterns = [
path('', views.hello_world, name='hello_world'),
]
to get to http://127.0.0.1:8000/home/
else you need to goto http://127.0.0.1:8000/home/home/ for the current url
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') ,
]