debug-toolbar spoiled my urls - python

I'm a newbie to Django and now I'm trying to make a simple webshop using it. Today I realized that I need some debug tool, so I've chosen django-debug-toolbar. I setup it just like it's explained here - How do I see the Django debug toolbar?. But when I set DEBUG to True I get a message -
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in urlconf, Django tried these URL patterns, in this order:
^__debug__/m/(.*)$
^__debug__/sql_select/$ [name='sql_select']
^__debug__/sql_explain/$ [name='sql_explain']
^__debug__/sql_profile/$ [name='sql_profile']
^__debug__/template_source/$ [name='template_source']
The current URL, , 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 app's urls.py:
from django.conf.urls import patterns, url
urlpatterns = patterns('ecommerce.views',
url(r'^profile/$', 'profile'),
url(r'^login/$', 'login_user'),
url(r'^logout/$', 'logout_user'),
url(r'^registration/$', 'registration'),
)
As far as I can see now django looks for appropriate urls not in my app's urls.py, but somewhere else.

Related

Django server returning a 404 out of nowhere

I'm quite new to Django and coding to be honest!
I'm facing a problem that appeared out of nowhere when I was finishing a website I can't seem to find anything here that helps with my case.
The problem goes with when I try to run the server with python manage.py runserver it gives me this error :
System check identified no issues (0 silenced).
July 27, 2022 - 17:30:51
Django version 4.0.6, using settings 'sitewilza.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /
[27/Jul/2022 17:30:53] "GET / HTTP/1.1" 404 2573
Not Found: /
[27/Jul/2022 17:30:57] "GET / HTTP/1.1" 404 2573
and the server returns this:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in sitewilza.urls, Django tried these URL patterns, in this order:
admin/
sobremim [name='sobre']
formacao [name='formacao']
contato [name='contato']
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.
the problem is I did not change anything in both my urls.py, here they are :
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('website.urls')),
]
&
from django.urls import path
from . import views
urlpatterns = [
path('sobremim', views.sobremim, name='sobre'),
path('formacao', views.formacao, name='formacao'),
path('contato', views.contato, name='contato'),
]
note that i was editing my contato.html file using a anchor to set up a Instagram forward link.
I don't know if my questing is well presented or not, but I hope you guys can understand and thank you in advance for your time in helping me.
So see, you have to understand django flow cycle and then you will be able to develop your website properly.
Here is what you doing in your urls.py when you are requesting your django local server is you are calling urls.py of website app so but you are not telling django what to do exactly whem / is called.
This will fix your problem:
from django.urls import path
from . import views
urlpatterns = [
path('', views.sobremim, name='sobre'),
path('formacao', views.formacao, name='formacao'),
path('contato', views.contato, name='contato'),
]
Update your urls.py file of website app and you will get your response.

Can't see the django home page

I'm new to django, thus the question.
I've a django project set up with two apps both of which seem to work fine. Just that I can't reach the homepage - which should be the default django page. I get the following error,
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in core.urls, Django tried these URL patterns, in this order:
admin/
^aggregator/
^bouncer/
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 urls.py
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^aggregator/', include('aggregator.urls')),
url(r'^bouncer/', include('bouncer.urls')),
]
What am I missing here?
you are missing the path to your home directory in the urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^aggregator/', include('aggregator.urls')),
url(r'^bouncer/', include('bouncer.urls')),
url(r'^$', views.yourhomeview),
]

Polls application -- django tutorial not working

I followed the instructions in the tutorial
I made one change for debugging, here are the files:
mysite1\urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^abc/', include('polls.urls')),
url(r'^polls/', admin.site.urls),
url(r'^admin/', admin.site.urls),
]
File: mysite1\polls\urls.py
from django.conf.urls import url
from .import views
urlpatterns = [
url(r'^&', views.index, name='index'),
]
Now if I go to the site http://127.0.0.1:8000/polls/ then it shows the login page same as going to the site http://127.0.0.1:8000/admin/.
However, if I go to the site http://127.0.0.1:8000/abc/ it gives me the following:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/abc
Using the URLconf defined in mysite1.urls, Django tried these URL patterns, in this order:
^abc/
^polls/
^admin/
The current URL, abc, 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.
Can someone guide me what I am doing wrong?
In mysite1\polls\urls.py It should be
url(r'^$', views.index, name='index'),
Notice that your code had an & instead of $. $ indicates a end-of-string match character.
I had a few issues with this, maybe it'll help someone. My VS code was running python 2.7 so the first line on page urls.py in the web project folder (not the polls folder) I had to change to "django.conf.urls import include, url" from "from "django.urls import include, path". I had to include .conf. and urls, path was not working and it was not working without "conf".
Another issue I had on this same page is I had to correct it to "urlpatterns = [url('', include('hello.urls'))..." from "urlpatterns = [path('', include("hello.urls"))". Path was not working so I got this to work.
The third thing is, Notice that there is a '' in the code. It should be blank otherwise when you go to url http://127.0.0.1:8000/ it doesn't redirect to views.py in the polls folder.
I hope this helps someone. Thanks

Django: index.html url cannot be found (Django polls tutorial)

I can't seem to get the tutorial at https://docs.djangoproject.com/en/1.6/intro/tutorial03/ to work. I get the following error when trying to access http://127.0.0.1:8000/index.html or http://127.0.0.1:8000/
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/index.html
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, index.html, didn't match any of these.
I have /mysite/urls.py set to:
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
And index.html is in /polls/templates/polls/index.html
The URLs in your urls.py are the ones you can go to; so either
http://127.0.0.1:8000/admin/
http://127.0.0.1:8000/polls/
Provided both those subapps (admin and polls) define a view for the empty string ("^$"), which I believe both of them do.
The fact that one of those views happens to use a template named "index.html" doesn't mean that that filename is also used in URLs.

404 error in django when visiting / Runserver returns no errors though

When I syncdb and runserver everything works correctly in Django, but when I try to visit the webpage that it is on http://127.0.0.1:8000/ it returns a 404 error.
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in MyBlog.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
The strange part is that when I visit /admin on the page it works fine. I dont understand what is failing here. Any help would be awesome!
You need an URL route to the homepage. The urlpatterns variable in MyBlog.urls should have a tuple pair like (r'^$', app.views.show_homepage), where show_homepage is a function defined in views.py. For more info about the URL dispatcher, you can read about it here: https://docs.djangoproject.com/en/dev/topics/http/urls/
Check out chapter 3 of Django's Writing your first Django app tutorial.
In short, you need to specify (in urls.py) which code Django should run for particular URLs; there are no default URLs defined (you'll see a line including the admin URLs in urls.py).
Edit your urls.py so it looks something like
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name="home.html"),
)
(you'll also need to create home.html in one of the directories specified in TEMPLATE_DIRS)

Categories