Django Page Not found error : Sudden in process of learning - django

I was in motion of learning Django, suddenly encountered Page not found Error in all pages.
This is my URL pattern file code:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^analysis/', include('analysis.urls')),
url(r'^music/', include('music.urls')),
]
but while accessing any of the pages page not found error is coming:
I have run the server on port 8084,
python .\manage.py runserver 8084
Accessing urls:
http://127.0.0.1:8084/admin
http://127.0.0.1:8084/music
http://127.0.0.1:8084/analysis
All of the views are available and pages were previously displayed but now it is not working. I have tried re-starting the server also but no help.
Kindly suggest me what could be the possibility of error.

Try running the runserver like this:
python manage.py runserver 8084

Related

First view in DJANGO tutorial -> Page not found (404)

I was doing tutorial "Writing your first Django app, part 1" and I got stuck in "Write your first view". I have fulfil all instructions regardings files. When I go to http://127.0.0.1:8000/ then I can see "The install worked successfully! Congratulations!" but if I go to http://localhost:8000/polls/ then I see:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/polls/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
admin/
The current path, polls/, didn’t match any of these.
In this case according instructions I should see "Hello, world. You're at the polls index". I attached 2 files content and 2 interesting screens (why does it emphasize?).
views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
I was looking answer in Stack Overflow (also in hints) or YouTube but unfortunately without success. Interesting but in another computer it works, but on my laptop not.
So you are doing the URLS incorrectly, or partially at least.
You need to create another app in django called polls:
python manage.py startapp polls
Then in the polls/urls.py file, include an extension for /polls, that references your view in polls/view.py:
urlpatterns = [
path('/polls', views.<view-name>, name='Polls URL')
]
Then it should work, otherwise you are doing something wrong and need to elaborate on our problem.
Note that Django's DEBUG should be True when developing at all times, so you can see the full error log. DEBUG=FALSE is used if you have a webapp public (aka deployed/in production.
Subject closed. Solution -> Bad configuration urls.py file in mysite and polls. Check content both files in tutorial context.

Django redirecting from unknown reason

I was working on this app some time back and I have returned and for the life of me cannot see where a redirection is occurring.
From starting the app as below and navigating to the base URL, you can see attempt to reach '/Sites/' url
python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
June 20, 2018 - 16:35:05
Django version 1.11.13, using settings 'SysMan.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /Sites/
[20/Jun/2018 16:35:07] "GET /Sites/ HTTP/1.1" 404 2263
The urls file is as below.
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic.base import RedirectView
from django.contrib.auth import views as auth_views
admin.site.site_header = 'Rio System Management'
admin.site.site_title = 'Rio SysMan admin'
admin.site.index_title = 'SysMan Administration'
urlpatterns = [
url(r'^$', RedirectView.as_view(url='/main/', permanent=True)),
url(r'^admin/', admin.site.urls),
url(r'^main/', include('apps.main.urls')),
url(r'^asnreg/', include('apps.asnreg.urls')),
]
I have run grep against the project folders for Sites with nothing of meaning being returned there.
Manually browsing to the URL's as below get me where I need to be.
http://127.0.0.1:8000/admin/
http://127.0.0.1:8000/main/
http://127.0.0.1:8000/asnreg/
Just can't figure why
http://127.0.0.1:8000/
redirects me to
http://127.0.0.1:8000/Sites/
I have looked at the various views file with nothing obvious there either
I did copy/paste the folders into a new virtenv. Could something be lingering in the DB??

Django Admin - 404 Error when logging in

When going to login to the Django admin on my page, I geta 404 error and a "/admin/login/ url is not defined".
I only get this error while in the Production of my project - it works just fine locally. I am using A2 hosting and their support team has not been able to help me solve this problem.
The stack trace as well as the error url are seen in the second image.
Let me know if you need to see any code, I am more than happy to share I just dont want to be here all day posing all of my .py files when most of them wont matter anyways.
Code by request:
urls.py
from django.contrib import admin
from django.conf.urls import url, include
from django.views.generic.base import TemplateView
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^students/', include("students.urls")),
url(r'^$', TemplateView.as_view(template_name="home.html"), name="home"),
url(r'^home/$', TemplateView.as_view(template_name="home.html"), name="home"),
url(r'^about/$', TemplateView.as_view(template_name="about.html"), name="about"),
url(r'^how_to_sponsor/$', TemplateView.as_view(template_name="how_to_sponsor.html"), name="how_to_sponsor"),
url(r'^malawi/$', TemplateView.as_view(template_name="malawi.html"), name="malawi"),
url(r'^stories/$', TemplateView.as_view(template_name="stories.html"), name="stories"),
url(r'^donations/$', TemplateView.as_view(template_name="donations.html"), name="donations"),
url(r'^staff/$', TemplateView.as_view(template_name="staff.html"), name="staff"),
url(r'^malawi_education/$', TemplateView.as_view(template_name="malawi_education.html"), name="malawi_education"),
]
admin.site.site_header = 'Maphunziro Project'
UPDATE:
I ran a migration and now the login screen displays like it normally does - I am still getting the login issue however.
Could this be a dependency problem? I have all of the same dependencies installed on the server as my localhost version but maybe I'm missing one that is required for production.
Try the address without the trailing slash 'www.educate-malawi.com/admin/login'. You can take a look at the documentation regarding the APPEND_SLASH here.

How to setup URL.PY Code for Django 1.11 on Ubuntu 16.04

I am very new to coding and started 2 days back, and using the Ubuntu distro since yesterday. I have been following a youtube video on how to build a website using python, and in the video he is using a Mac. It has been similar for the most part, but I have been able to google the few differences and fix them on my own. I am having trouble with the code that you use for the url.py file. Images of the error have been attached.
*The code edit I did in the text editor.
*The error I get on my Ubuntu terminal.
Any help on this matter is greatly appreciated.
Current Code
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^login/$', login, name='login'),
]
Error When running "python manage.py runserver"
NameError: name 'home' is not defined

Django urls.py not updating to include heroku url?

I am trying to deploy my Django app on Heroku and I am following the tutorial but when I go and try to open the website with:
heroku open
I receive the error :
Request URL: http://nameless-dawn-7713.herokuapp.com/
Using the URLconf defined in crunchWeb.urls, Django tried these URL patterns, in this order:
^crunchApp/results$
^crunchApp/contact$
^admin/
The current URL, , didn't match any of these.
Even though before running " heroku open" my URLs.py file looks like this (saved) :
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('crunchApp.views',
url(r'^crunchApp/results$', 'results'),
url(r'^http://nameless-dawn-7713.herokuapp.com/$', 'contact'),
url(r'^crunchApp/contact$', 'contact'),
url(r'^admin/', include(admin.site.urls)),
)
I think I might have to change the urls.py before the command:
git commit -m "my django app"
but I dont know the URL that it will need until the command:
heroku create
Any ideas of what to do?
Why do you have url(r'^http://nameless-dawn-7713.herokuapp.com/$', 'contact') in your urls file ? In fact, these URLs should be relative to your application, and you should not update this file before uploading to Heroku (if it works locally, it should work on Heroku without any change to this file).
If you want to connect the contact view to your base URL (http://nameless-dawn-7713.herokuapp.com/), you should use something like:
url(r'^$', 'contact')
Hope this helps !