Django Admin page not displaying - django

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.

Related

Can I deploy a Django App if there is no "" (empty) url?

I'm trying to deploy a Django App with railways for the first time and I was wondering where exactly will be my landing page. So basically my urls.py looks something like this:
path('home/', views.home, name="home"),
path('blogposts/', views.blogposts, name="blogposts"),
path('posts/', views.posts, name="posts"),
After deploying my Blog website, let's say with the domain 12345xxx.com, where will I land?
You will get an error if you don't include a folder in the URL, as the URL patten won't be matched and the existance of non-admin URLs stops the default django page from showing. This will be either a 404 error or a 'Django tried these URL patterns, in this order:' type error if you have DEBUG=True on in settings.
Note that you don't have to provide a path (the path can be an empty string), and views can have multiple paths. In this case, perhaps
path('', views.home, name="home"),
path('home/', views.home, name="home_folder"),
path('blogposts/', views.blogposts, name="blogposts"),
path('posts/', views.posts, name="posts"),
would avoid an error.

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 Admin Panel not working

I am using Django 1.7 on OSX Yosemite.
For some reason, when I go to my default project URL /admin, the administration panel isn't coming up. Instead, I get a 404 as shown below.
I have url(r'^admin/', include(admin.site.urls)) in my urlpatterns in urls.py, so why isn't this working?
Completely lost here.
Try putting a '/' after admin. The regex in your urls.py checks for a '/' after admin. Eg:'https://yourdomainname/admin/'

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')),
)

Page not found at /archive/

EDIT: Figured it out, please see bottom.
I'm writing a simple blog app in Django and deploying it locally using this guide. I've completed the guide and everything was nominal so I decided to extend the functionality to view an archive of blog posts. This is how the index functions at the moment, but I wanted to move it to /archive/. I went to the tutorial again to get refresh my memory and it said I had to do three things:
Write the root URLconf in urls.py
Write the view function in views.py
Write the templates for the views
I edited the URLconf to look like this:
urlpatterns = patterns('',
#other patterns
url(r'^archive/', 'RehabLog.views.archive'),
)
I edited my views.py to add this function:
def archive(request):
posts = Post.objects.filter(published=True)
return render(request, 'RehabLog/archive.html', {'posts':posts})
I've saved it all and restarted foreman. When I load the page I get a 404 error which tells me No Post matches the given query. What am I missing out on?
Answer
I remembered reading the the order of your URLConfs was very important.
Previously I had:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'RehabLog.views.index'),
url(r'^(?P<slug>[\w\-]+)/$', 'RehabLog.views.post'),
url(r'^archive/', 'RehabLog.views.archive'),
)
Whereas now I have:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^archive/', 'RehabLog.views.archive'),
url(r'^$', 'RehabLog.views.index'),
url(r'^(?P<slug>[\w\-]+)/$', 'RehabLog.views.post'),
)
Which now works. Could anyone explain why?
/archive/ URL was first-matched by url(r'^(?P<slug>[\w\-]+)/$', 'RehabLog.views.post') so your actual rule url(r'^archive/', 'RehabLog.views.archive') was never reached. When you changed the order the first rule matched was the right one.