Django Admin Panel not working - django

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/'

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 Management command for Activating/Deactivating admin site

I would like to know if it's possible to 'Activate' and 'Deactivate' the admin site using a custom management command and what i mean by deactivating is commenting the line containing the path of admin.site.urls in the main urls.py file.
Or if there is a better way to do this.
I think the best way to do it - write custom middleware.
You can detect if current request is request to admin site (for example request.path.startswith('/admin')) and return 404 error if you disable you admin page.
When do you want to deactivate the admin urls? For example if you want to deactivate admin site urls for production, you can add a control to urls.py checkin if settings.DEBUG is False.
urlpatterns = [
...
]
if not settings.DEBUG:
urlpatterns += [
path('basic-admin/', basic_site.urls)
]

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

why my urls.py does't work with Django

Today when I code my blog with 'Building_a_blog_in_30_mins_with_Django_Screencast',I meet some problems.When I click the title with the article,it can't appear the right page.!
Page not found (404)
Request Method: GET
Using the URLconf defined in myblog.urls, Django tried these URL patterns, in this order:
^$
^(?P<pk>\d+)/$
^admin/
^admin/doc/
The current URL, app/1, 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.
and it's my urls.py:
url(r'^$',ListView.as_view(queryset=Post.objects.all().order_by("created[:2]template_name=" blog.html")),
url(r'^(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/doc/', include('django.contrib.admindocs.urls'))
I doesn't konw what is going on with it.Please help,thanks!
You need to add 'app/' in your url.
url(r'^app/(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")),
Or may be you need to define these urls in urls.py of your app (named app ?) and include it in sites main urls.py
url(r'app/', include('app.urls'))