I have the following code in the urls.py file
urlpatterns = patterns('ecomstore.accounts.views',
(r'^register/$', 'register', {'template_name':'registration/register.html', 'SSL':settings.ENABLE_SSL}, 'register'),
(r'^my_account/$','my_account', {'template_name':'registration/my_account.html'},'my_account'),
(r'^order_details/(?P<order_id>[-\w]+)/$', 'order_details', {'template_name':'registration/order_details.html'}, 'order_details'),
(r'^order_info//$', 'order_info', {'template_name':'registration/order_info.html'},'order_info'),
)
All the redirects work i.e. /register/, /my_account/, etc except for /order_info//. I'm getting a 404 page not found error and I'm not sure why this is any different than the others.
It's working on my development server, but not apache for some reason if that has anything to do with it.
Related
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.
So had zero issues with my Django and React URL routing in dev, but now that I am trying to move to production, running into all kinds of issues.
Yes, I suck when it come to regex. It looks like a cat walked on a keyboard. Definitely something I need to sit down and commit to learning.
In dev, my catch-all was just the following which worked perfectly:
url(r'', TemplateView.as_view(template_name='index.html')),
In production, I got Uncaught SyntaxError: Unexpected token <. This, as it was explained to me, had to do with JS being caught in the url instead of index.html and that the JS needed to "pass through". I was told to try:
url(r'^$', TemplateView.as_view(template_name='index.html')),
This worked. The web application loaded and I was able to navigate.
Another problem came up, however, when it came to verification emails links. I am running into issues with Page not found (404) which, again, wasn't an issue in my dev setup.
The email links look like the following:
https://test.example.com/auth/security_questions/f=ru&i=101083&k=6d7cd2e9903232a5ac28c956b5eded86c8cb047254a325de1a5777b9cca6e537
What I get back is this:
Page not found (404)
Requested URL: http://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D6d7cd2e9903232a5ac28c956b5eded86c8cb047254a325de1a5777b9cca6e537/
My react routes are the following:
<App>
<Switch>
<Route exact path='/auth/security_questions/f=:f&i=:id&k=:key' component={SecurityQuestions} />
<Route exact path='/auth/*' component={Auth} />
<Route exact path='/' component={Auth} />
</Switch>
</App>
This should render /auth/security_questions/... route.
My urls.py is the following:
urlpatterns = [
# API authentication entry point
url(r'^api/auth/', include('authentication.urls', namespace='signin')),
# Any requets that come through serve the index.html
# url(r'^$', TemplateView.as_view(template_name='index.html')),
] + static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
Also, the authentication.urls:
urlpatterns = [
url(r'^security_questions/', SecurityQuestionsAPIView.as_view(), name='security_questions'),
]
It seems like Django is trying to handle the routing, there obviously isn't a route that matches, when really it should just render index.html and let react-router-dom take over to send requests to the API from the FE. Thus, it seems I need to make a catch-all that lets JS through.
I came across this question which seemed relevant: react routing and django url conflict. So I added the following so that I have a / catch and then "everything-else" catch-all.
# match the root
url(r'^$', TemplateView.as_view(template_name='index.html')),
# match all other pages
url(r'^(?:.*)/?$', TemplateView.as_view(template_name='index.html')),
Still won't render the verification links. Tried a few other variations for the last-catch all URL:
Django route all non-catched urls to included urls.py
url(r'^', TemplateView.as_view(template_name='index.html')),
Results in Uncaught SyntaxError: Unexpected token <
django catching any url?
url(r'^.*', TemplateView.as_view(template_name='index.html')),
See the preceding.
So going to dig into Django, regex, and try to sort this out, but in the mean time...
What am I doing wrong here?
Ok, was almost there. I modified:
url(r'^(?:.*)/?$', TemplateView.as_view(template_name='index.html')),
To this:
url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),
Which prevented the Uncaught SyntaxError: Unexpected token < error. It would load parts of the web application, but not in its entirety. That issue was due to URL-encoding so I had to clean up the formats of my URLs. Question I had about it here:
Prevent URL encoding that is removing equals signs from URL
Now everything seems to be loading correctly.
I'm a newbie in Django and just started looking at it before a day by installing Django 1.10 on my local.
I've followed all the instructions of this link https://docs.djangoproject.com/en/dev/intro/tutorial01/. However I'm continuously getting this error:
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/polls/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, polls/, didn't match any of these.
I've created polls app to getting started.
To make a start, I went with view.py, here is the code:
polls/views.py
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World!")
Here is my code for urls.py:
polls/urls.py
from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
)
And here is the urls.py in root:
mysite/urls.py
from django.conf.urls import patterns,include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
I've spent good piece of time to find out the solution, found that this question has been asked for many times,so tried with those solutions as well but none of them worked for me.
I can't find out what I'm missing here so please draw my attention to the gap.
I think you have edited the wrong file when trying to change the root url config.
Make sure you are editing the root url config in mysite/mysite/urls.py (the directory containing settings.py) not mysite/urls.py (the directory containing manage.py).
As general advice, install the latest release, currently 1.9. Don't use 1.10, which is under development. Make sure that you are following the tutorial for 1.9, because the tutorial changes for different versions. For example, your mysite/urls.py doesn't match the tutorial for 1.9, as the urlpatterns should be:
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
In settings.py you have a setting name INSTALLED_APPS-
Adds you app i.e. polls to it.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
....
'polls',
]
It's working. Go to your url bar and type your app name:
http://127.0.0.1:8000/home
My app name is home. It will work.
If you want to set your app as your default page then import views from your app.
Like
from home import views
then write
url(r'^$', views.index),
inside.
It will set the views as your default page
http://127.0.0.1:8000/
When you type this it will redirect to your views.
I had the same problem as described. Running a Windows machine.
It turned out, that the virtual environment I was using had not been configured properly (or maybe I had forgot to activate it before installing Django) and the interpreter and django-admin were fetched from the wrong path by CMD.EXE.
If it appears as if Django is "ignoring" your urls.py - try deleting everything, re-creating the virtual environment, activating it and re-installing Django afterwards.
Make sure you have path("admin/", admin.site.urls) in your main url settings.
change the mysite/url
from django.conf.urls import patterns,include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^&', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
Then run your server and visit 127.0.0.1/8000.
This should take you to the index of your website.
or you leave your code as it is and run 127.0.0.1/8000/polls on your browser
if #Alasdair answer does not work, and it seems your working on correct files, just restart your server
The path in Django 2.2 does not support regular expression , I was using, path('(?P<id>\d+)/share/', views.mail_send_view) , so getting error, now changed to this, path('<int:id>/share/', views.mail_send_view). Now not getting any error. For more info please follow django's official documentation.
I too had same problem going through the official docs tutorial. I was using cloud 9. What I realised before I was able to solve this problem was that while creating the workspace I already chose django(ie by the time my workspace was created, django had already been installed) And going through the tutorial, I again executed $ django-admin startproject mysite thereby having another layer of django with multiple directories and unavoidably the confusion. My solution was to delete everything and start all over.
Checklist:
Make sure to run the server
>>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
February 01, 2020 - 15:04:46
Django version 3.0.2, using settings 'corona.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Open the browser with cmd running, http://127.0.0.1:8000/polls
should be added to the url.
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.
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)