Django Admin - 404 Error when logging in - django

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.

Related

Django URL order

iam stuck again I hope I will get useful help this time too.
Iam trying to run the app but it gives me URL configuration error something like this:
Using the URLconf defined in pyshop.urls, Django tried these URL patterns, in this order:
admin/
products/
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.
I see a similar query in this platform but I couldn't find my answer
Iam using Django version 2.1
My code in pyshop.urls is:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('products/', include('products.urls'))
]
You don't route / anywhere, and
The empty path
implies that's exactly where you're visiting.
You'll either need to
add e.g. path('', SomeHomepageViewMaybe),
or remove the /products/ prefix to make the products app a "main" app (not that there's a concept like that in Django),
or just navigate to /products/ instead

Django Admin page not displaying

A couple days ago I was able to get to the django admin login page but today when I try to hit 127.0.0.1:8000/admin I get redirected to 127.0.0.1:8000/admin/login/?next=/admin/ which brings up the DRF view for JSON testing
Am I missing something? I am not sure what would have changed. I looked at the last few days of version control and dont see where anything changed.
Once it happened to me when I unintentionally included rest_framework.urls and admin.site.urls in the same url. Such as:
url(r'^admin/', include('rest_framework.urls')),
url(r'^admin/', include(admin.site.urls)),
So, make sure these are included in defferent urls such as:
url(r'^api-auth/', include('rest_framework.urls')),
url(r'^admin/', include(admin.site.urls)),
Came across a similar issue. For mw, what happened was I had my route for the API registered at the root like this:
path('', include('app.urls'))
which made the admin page render in the DRF view. Moving the app to a directory path at:
path('app', include('app.urls'))
fixes it.

Django URLs management

I'm a full beginner on Django. Therefore, I'm sorry if my question is not making so much sense.
I'm studying Django tutorial - step 1. I installed properly Django and created my first Django project named 'vanilla'. The urls.py script of the vanilla project is
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
When I start Django with this 'vanilla' project and start the development server at http://127.0.0.1:8000/, I correctly see the start page (with a rocket).
In a second project that I named 'djtutorial', I created as requested in Django tutorial - step 1 a 'polls' app. As requested, I modified urls.py file in djtutorial\polls which now has following content:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
If I start the server the url http://127.0.0.1:8000/polls/ is working properly. However, if I launch the root url of the site (i.e. http://127.0.0.1:8000/), I now have a 404 error.
Why is the 'root url' of the site now hidden?
There wasn't any root URL at all. Main page informing you that your project is created properly shows up only if you don't have any view of your own added to urlpatterns. When you create any page, this welcome page stops showing up and that is expected.
If you want to show your own page on root of your website, use this in your urlpatterns:
path('', >>VIEW OR INCLUDE HERE<<),

CSRF verification failure when trying to upload an image from django-ckeditor on staging server

Django-ckeditor has an option to insert and upload images directly from the editor. This works on local/development machines, but on remote servers Django throws a 403 error, CSRF verification failed. This happens in the admin backend, and I am having no other similar problems. Does anyone know what I am doing wrong? Any help would be greatly appreciated. Thanks
I had this issue because of url(r'^sys/cke/', include('ckeditor.urls')) was included to urlpatterns after less restrictive pattern (namely, url(r'^', include('cms.urls'))).
Thus, when reverse url resolver was used to build absolute url for ckeditor_upload it worked properly, but when url resolver was to find proper view for request, the request went not to the ckeditor's view with #csrf_exempt, but to view with first matched pattern. The confusion was because the 403 Forbidden error message has no trace of the view being executed.
Issue is still open.
https://github.com/shaunsephton/django-ckeditor/issues/84
Better to exempt the csrf verification.
I don't know if you already solved it, but I got the same problem. The issue was related to the django version. So you need to add this to your urls.py:
if django.VERSION >= (1, 8):
urlpatterns = [
url(r'^', include('blog.urls', namespace="blog")),
url(r'^admin/', include(admin.site.urls)),
url(r'^ckeditor/', include('libs.ckeditor_uploader.urls')),
]
else:
from django.conf.urls import patterns
admin.autodiscover()
urlpatterns = patterns(
'',
url(r'^', include('blog.urls', namespace="blog")),
url(r'^admin/', include(admin.site.urls)),
url(r'^ckeditor/', include('libs.ckeditor_uploader.urls')),
)

My DJango app is responding to /static urls

Update
I figured out what was causing the stylesheets to become invisible, though I don't quite understand it all. I set DEBUG=False in settings.py to test the error handling as described in the tutorial. Somehow setting debug to false causes the static files not to be locatable. I will look further in the configs to see if I can get a clear understanding why. Until then, please feel free to answer or comment with additional info. I am still learning!
Update
I'm going through a DJango tutorial from here and I hit a roadblock. I'm up to tutorial 3 where they explain how to refactor your urls.py file when I try loading up the admin site to make sure I haven't broken it. Sure enough it looked all wierd because it was missing the stylesheets. Stylesheets are pulled from here:
http://127.0.0.1:8000/static/admin/css/base.css
When I hit that link in my browser I get the custom 404 page I configured for my app. The stylesheets were working prior but I'm not sure which change broken them. I went through my urls.py file and reverted all of the polls specific url configs to no avail. Here's my current urls.py under hellodjango (the name of my project.)
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from django.http import HttpResponse
admin.autodiscover()
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
def page_not_found(request, template_name='404.html'):
return HttpResponse("Could not find the resource you asked for...")
handler404 = 'hellodjango.urls.page_not_found'
and here's the urls.py under my polls directory:
from django.conf.urls import patterns, url
# Uncomment the next two lines to enable the admin:
urlpatterns = patterns('polls.views',
url(r'^$', 'index'),
url(r'^(?P<poll_id>\d+)/$', 'detail'),
url(r'^(?P<poll_id>\d+)/results/$', 'results'),
url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
Help?
It looks like you don't have a URL pattern for /static. As such, the static/admin/css/base.css URL doesn't match any pattern, and so you get a 404. Try something like this:
from django.conf.urls.static import static
# ...
urlpatterns = patterns('',
# ...
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
# ...
This should work for you -- go to /static/foo.css, and you should see your CSS.
It's worth noting that this is discouraged in a production environment. For your tutorial app, though, it'll work.
The staticfiles app provides a custom runserver management command that automatically serves the static files, are you sure you have the following in your settings?
INSTALLED_APPS = (
# ...
'django.contrib.staticfiles',
)
In production, you'll use the collectstatic management command that finds all of the static media and dumps it into STATIC_ROOT (this is the only purpose for this setting - it isn't used or needed during development).
Glad you figured it out. Here's why it works like this.
django.contrib.staticfiles overrides the runserver management command so that the static files are served automatically. To remind people that they shouldn't be using django to serve static files, this only happens when DEBUG = True, as you found out.
The documentation of the overridden management command explains that you can use the --insecure flag to make this work no matter the state of the DEBUG setting.