Django redirecting from unknown reason - django

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??

Related

Page not found error - Writing your first Django app, part 1

I have installed Django 2.2.5 in my conda environment and I'm following the Django tutorial for Writing your first Django app, part 1
I followed the steps exactly but I'm getting a Page Not Found error when I try to access the polls/ url.
My root directory structure is like this
mysite/
manage.py
db.sqlite3
urls.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
polls/
migrations/
__init__.py
admin.py
apps.py
models.py
tests.py
urls.py
views.py
And my view is like this
D:\TEMP\djangotest\mysite\polls\views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World. You're at the polls index")
My two urls files are like this
D:\TEMP\djangotest\mysite\polls\urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
D:\TEMP\djangotest\mysite\urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
And I run the app from the environment like this
(py3.6) D:\TEMP\djangotest\mysite>python manage.py runserver
But when I go to the url indicated in the tutorial it give the 404 error - page not found from the console
October 21, 2019 - 16:23:13
Django version 2.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /polls
[21/Oct/2019 16:23:19] "GET /polls HTTP/1.1" 404 1954
From the browser it look like
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.
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.
Your main urls file is in the wrong directory. It looks like you've created a separate urls.py in the base "mysite" directory; instead you should have edited the existing one in the "mysite/mysite" directory. The one you've created isn't being used at all.

Why can't I add data to models in Django database?

I can't data to any of the schemas on my database. It gives error HTTP 400 when I click on save. Applicable to all schemas and models.
Images attached.
I expect it to add the data to the model but it says that the page isn't working and returns error 400.
And also, I created another Django project and I was able to add users there. I matched the settings.py file for both the projects and I couldn't spot any difference. Is there some place else I should be looking?
urls.py ->
from django.conf.urls import include, url
from django.contrib import admin
from django.http import HttpResponse
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^chat/', include('chat.urls', namespace='chat')),
]
No error in the console log
[2019/05/27 08:33:58] HTTP GET /admin/login/ 302 [0.04, 127.0.0.1:39500]
[2019/05/27 08:33:58] HTTP GET /admin/ 200 [0.05, 127.0.0.1:39500]
[2019/05/27 08:34:00] HTTP GET /admin/login/rooms/add/ 200 [0.04, 127.0.0.1:39500]
[2019/05/27 08:34:00] HTTP GET /admin/jsi18n/ 200 [0.03, 127.0.0.1:39500]
Repository link-
https://github.com/AdityaAjay/Collabgator

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.

Django Page Not found error : Sudden in process of learning

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

how to overcome the following url issue?

Hello I am beginner learning Django I am triying to follow this tutorial:
https://docs.djangoproject.com/en/1.11/intro/tutorial01/
I created an app called Polls to test my site:
Since I dont have idea where to put the file called urls.py
I put this file at the following directories:
Django/mysite/polls/urls.py
Django/mysite/polls/migrations/urls.py
This file contains:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
And finally I added the following lines:
at this level:
Django/mysite/mysite/urls.py
this file contains:
from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^polls/', include('polls.urls')),
]
I dont know where is the issue but when I run:
Django/mysite$ python3 manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
April 21, 2017 - 15:59:43
Django version 1.10.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
I got in the page the following:
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:
^admin/
^polls/
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.
So I really appreciate support to overcome this issue,
thanks for the support
the urls.py doesn't go into the migrations folder.
Did you register your Polls app in the settings.py file? you need to add the name of the Polls app to the INSTALLED_APPS list.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'example: add app name here',
'polls',]
you then need to create a url.py file within your polls app.
polls/
urls.py
In that file you would add:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
the url you want to use in your browser would be something like this:
http://127.0.0.1:8000/polls