django-grappelli not working - python

I am unable to get django-grappelli working.
Below is what I did -
Installed using pip install django-grappelli.
Added 'grappelli' in INSTALLED_APPS before the 'django.contrib.admin' .
In urls.py, added URL definition url(r'^grappelli/', include('grappelli.urls')), before admin url, ie. url(r'^admin/', include(admin.site.urls))
Executed syncdb and collectstatic commands.
Now when I run command runserver, and browse localhost:8000/admin/, surprisingly I am getting the default admin.
I checked the request traffic in Google Chrome Network tab (in Developers Tool), and I don't see any request for url starting with Grappelli.
I don't know what I am doing wrong. I am using Django 1.4.1-final in virtualenv on Windows 7 machine.

I found the issue. Actually I had previously overridden the Admin Templates for branding my admin login and top page headers. So, in my template dir, there is admin dir with some custom templates (which I copied from django/contrib/admin/templates and edited as per my requirement). Due to this, Grappelli was not showing any of my changes...
I got the hint from here - https://stackoverflow.com/a/12193858/1284552
When I removed it, it worked as expected.
Also, I just need to visit the admin path, not the grappelli path as defined in Urls.py.

Resolved this issue after adding 'grappelli' at the top of 'django.contrib.admin'.
Adding to Lucian's answer, the documentation itself says,
Insert 'grappelli' at the top of 'django.contrib.admin'.
So INSTALLED_APPS will be,
INSTALLED_APPS = (
'grappelli',
'django.contrib.admin',
)
Taken from : http://django-grappelli.readthedocs.org/en/latest/quickstart.html

I had the same thing, I changed the order of the rows and all earned
'grappelli',
'django.contrib.admin',
make sure that the string 'django.contrib.admin' written 1 times

Related

Django admin static files magically served

I just setup a simple Django website for development, and commented out
path('admin/', admin.site.urls),
with STATIC_URL = '/static/' in the settings.py,
When I do python manage.py runserver 8100 and goto http://localhost:8100/static/admin/css/nav_sidebar.css, I see
this static file is magically severed.
What's really going on? I have not setup the static url serving in my urls.py yet? I also do not have another static server like NGINX.
I think the static files are served by e.g. NGINX. They are put to a location where they are accessible once you execute python manage.py collectstatic , and then Django does not care about them any more, because they are taken care off by your server. They are outsourced, so to say. Its a different service that handles them. So, the /static will be remain accessible regardless of the admin URLs. What you switch on and off with the admin URLs are the pages under /admin.
http://localhost:8100/admin
Will not work anymore, but
http://localhost:8100/static/admin
will stay untouched.
So from https://docs.djangoproject.com/en/3.2/howto/static-files/, when you set DEBUG=True, Django will automatically do collectstatics and server the static file thur the URLs for you.

I keep getting no changes detected when migrating app in Django

I am following this video tutorial to learn Django: https://www.youtube.com/watch?v=F5mRW0jo-U4&t=909s
I am at the "Your first app component" section where he creates an app and then migrates it. I have followed every one of his steps so far yet I keep getting the no changes detected error when I migrate the app
I have tried researching ways to fix this but it doesn't seem like there is any one right way to do it, it's more of a case by case basis. I've made sure my app is under the install_apps section in the settings. I've tried python manage.py makemigrations but that tells me there are no changes detected. I've tried "python manage.py makemigrations product" to be more specific but it tells me that App 'product' could not be found. Is it in INSTALLED_APPS?" even though it is in installed apps
currently this is my installed apps section:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'product',
after migrate and makemigrations command put your app name
like this
python manage.py migrate product
python manage.py makemigrations product
my case it's working
You didn't add your app name in 'Installed_Apps' in settings.py. Add this first and then run again.
for a proper migrations with 'python manage.py makemigrations' make sure that after creating your model class you save them before you typing any console code very important

django-newsletter - no runjobs in manage.py commands?

Hi I'm reading the docs for using django-newsletter.
And it says to call the following admin command to actually send the emails:
./manage.py runjob submit
In other parts of the docs it says runjobs instead of runjob.
Anyways, I'm not seeing either runjob or runjobs in the list of commands ./manage.py help, even though the 'newsletter' app is in installed_apps and I can access it in the admin.
What am I missing?
I was missing django_extensions in INSTALLED_APPS. The actual requirements for django-newsletter in INSTALLED_APPS are:
INSTALLED_APPS = (
...
'sorl.thumbnail',
'django_extensions',
'newsletter',
...
)

Default django project not showing django templates

I started a new Django project with a new superuser. While I am able to access the admin interface, it does not have any of the default CSS files. It is looking for them in an admin/ folder within my static/ folder, but I do not have an admin/ folder anywhere in my project. How can I add the default CSS files for the admin interface?
You don't need one unless you want to change the default styles.
Your static resources for admin interface located in your django installation folder (site-packages/django/contrib/admin/static/admin).
It will be automatically be used by django framework unless you've done some extra settings that ruined default behaviour.
check for the following items in your settings.py:
INSTALLED_APPS = (
...
'django.contrib.staticfiles',
...
)
...
STATIC_URL = '/static/'
...
If you want to add some extra static folder/files:
# define global static
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
You can also have in each app a static folder like this
your_project_folder/your_app_folder/static/your_app_name/[static_resources]
If you're on production server and not development consider also adding a proper STATIC_ROOT like this
STATIC_ROOT = "/var/www/example.com/static/"
in your setting file or production server specific settings location.
At last check for django docs for specific version that you're using
mine in 1.8
Try to setup your STATIC_ROOT and your STATIC_URL.
After that run:
python manage.py collectstatic

Django : static files not loading

My django project contains a folder STATIC in which there are it's child folders css, images, js and swf. My web-site can not locate these files raising a 404 in the development server running on the terminal.
I have a settings_local.py file in which I have set the path such as (running on ubuntu 11.04)
STATIC_ROOT = '/home/zulaikha/dust.bin/my_project/static/'
STATIC_SERVE_PORT = 80
The sample settings-local.py file from the client suggest suggest so
# static root
STATIC_ROOT = 'C:/Program Files (x86)/XAMPP/htdocs/static'
STATIC_SERVE_PORT = 8080
I have seen some similar issues but all regard STATICFILES which I read was introduced in Django 1.3
Where am I wrong and how can I correct myself?
If you are indeed using django 1.2 then you must install django-staticfiles. If you do not see it in the included requirements.txt from your client then he either did not freeze it out into the file, or was not using that feature and instead was just pointing at it via apache or another production server.
Follow these instructions from the docs. Specifically the basic section:
https://docs.djangoproject.com/en/dev/howto/static-files/
You will need to add staticfiles to your installed app. You should also not need to manually add a url since the django should do it automatically with the runserver command.
Also verify that it works locally first by not running with sudo or a custom ip and port
According to your comments there are two options here:
Contact the programmer who wrote the code and ask him.
Rewrite static serving logic with
django-staticfiles (Django 1.2 is enough)
django.contrib.staticfiles and Django 1.3
In the simplest form, this is the solution to the problem. In project urls.py include the following lines
urlpatterns += patterns('',
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.STATIC_ROOT,
}),
)

Categories

Resources