Django superuser admin - django

I can't load the admin login screen.
have opened a Web browser and went to “/admin/” on local domain http://127.0.0.1:8000/admin/
was supposed to open admin login window.

First, check if your Django server is running.You can do that, by typing python manage.py runserver in the terminal and then visiting http://127.0.0.1:8000/admin/ in your browser.
Second, check if the Django admin is enabled. Open settings.py in your project folder and check if INSTALLED_APPS list has the django.contrib.admin element.
Third, check if you have an admin.py file in your app directory. The code should looks something like this:
from django.contrib import admin
from .models import MyModel
admin.site.register(MyModel)
Fourth, Check for your login credentials in your Django settings. Go to your project's settings.py file and you have to have this code:
LOGIN_URL = '/admin/login/'
LOGIN_REDIRECT_URL = '/admin/'
And the last option is to try clearing your browser cache and cookies and restarting the server.

Related

The change in the django view is not reflected to the page until restarting uwsgi

I installed Django + Uwsgi + Nginx.
Project is running. But when i change something in the view, the change is not reflected to page until i restart uwsgi. Should i restart uwsgi everytime i make a change in the view?
But when i add time to view to show in the page. The displayed time is changing everytime i refresh the page.
My view is :
from django.shortcuts import render
from django.http import HttpResponse # added
from django.utils import timezone
def home(request):
return HttpResponse('This is the home page. 101' + str(timezone.now()))
My urls.py :
from django.contrib import admin
from django.urls import path
from godentiapp import views # added
urlpatterns = [
path('', views.home, name='home'), # added
path('admin/', admin.site.urls),
]
Should [I] restart uwsgi everytime [I] make a change in the view?
Yes, each time you change the source code, you need to restart the webserver, since the files are always loaded once. The Python interpreter will read the source file, and load it in memory. Changes the the file will not be reflected.
If you work with Django in development mode, for modifications to the sourcde file it will automatically restart the server [Django-doc]:
The development server automatically reloads Python code for each request, as needed. You don’t need to restart the server for code changes to take effect. However, some actions like adding files don’t trigger a restart, so you’ll have to restart the server in these cases.
But this is thus not done in production, and should not be done, since this can result in security risks.

Change header 'Django administration' text on nginx

I followed this question's answers to change my django admin panel title header.
I tried this:
There is an easy way to set admin site header - assign it to current
admin instance in urls.py like this
admin.site.site_header = 'My admin'
But it just works when I'm running the page via Python manage.py runserver
My question is how can I change the admin title header when I'm running the site via gunicorn and nginx
writing this code at the bottom of urls.py somehow worked:
admin.site.site_header = 'My admin'
If you already have an admin.py file started wherein you have registered your particular models, you can simply adjust these values there.
your_app/admin.py
# Simple admin setup
from django.contrib import admin
from .models import MyModel
# Register model
admin.site.register(MyModel)
# Tweak admin site settings like title, header, 'View Site' URL, etc
admin.site.site_title = 'My App Admin'
admin.site.site_header = 'My App Admin'
You can find all the attributes here.
follow the below steps to customize the site header and site title text of django admin login page :
1.)First import admin module in settings.py file like as below :
from django.contrib import admin
2.)In bottom of settings.py file add these lines:
admin.site.site_header = 'MY_SITE_HEADER'
admin.site.site_title = 'MY_SITE_TITLE'
The above method works in latest version of django i.e.1.11.3 till date.
You can make changes to parts of the admin by providing a template in an admin subdir of your templates directory to override what is provided by admin.
In this case, you'd want to provide a base_site.html template. You can see what the default one looks like here: https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base_site.html

How to open the attached files from django admin?

can anyone help me in how to make the attched files opened from django admin website?
this is my code:
IDAttached = models.FileField(upload_to='/documents/%Y/%m/',null=True, blank= True)
Thanks in advance.
In order to see what the user of your django site uploads to the database you need to register your models.py of the app to the admin interface. For instance say you have models.py as below:
class ABC(models.Model):
ABCFILE=models.FileField(upload_to='<path>/%Y/%m/%d')
create an admin.py file inside your app folder and the following code:
from equipo.<your_app_name>.models import *
from django.contrib import admin
admin.site.register(ABC)
after this you be be able to see it on your admin interface.
If you have set MEDIA_URL correctly in your settings.py you should be able to get an address for those files at my_model.IDAttached.url
Django a runserver should display them for you in development but in production you'll need to configure your web server to display the contents of MEDIA_ROOT itself.

Redirect in Django admin page

In my django project, after activating the admin application, I canno't get access to the page localhost/soundaxis/admin because I'm redirected to localhost/admin.
I think the problem has to do with the fact that the project was not located at the base address.
Urls.py:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^soundaxis/', 'views.index.home'),
(r'^soundaxis/admin/', include(admin.site.urls)),
)
Start the server by typing the following in the base dir:
python manage.py runserver
then go to http://localhost:8000/
Its rather complicated to get the project to run off another subdirectory so I suggest running it from the base, especially during development. Later in the game you can try work it from a subdir if required, but better yet would be subdomain.

Django + socialauth: login with openid or admin

i'm trying to implement the socialauth module to my django project, but i get a bit confused on its relation toward the admin site.
My problem: the #login_required decorator redirects me to the admin login page instead of the accounts/login/ page to log in via openid.
how do i offer the possibility to the user to log in via admin or openid?
thanks
the solution:
in settings.py, change LOGIN_URL = 'admin' to LOGIN_URL = '/accounts/login/'
in urls.py add (r'^accounts/', include('socialauth.urls')),