am installing the django-admin-tools module to enhance the default django admin with custom dashboard and menus. I have read the docs like a bazillion times
Set up everything the way docs say, but am still merely seeing the Django Admin the SAME WAY is was before I'd even though of django-admin-tools.
What could be wrong?
Am running Django 1.3 and using OpenSuse 11.3
If it helps, the order of apps in my settings.py is like:
INSTALLED_APPS = (
'admin_tools',
'django.contrib.admin',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#'grappelli', #for a sweet django admin look
# 'django.contrib.admindocs',
'django_extensions',
'fpui', #the footprint front-end ui app
)
More Parts of my settings.py in relation to this problem:
ROOTDIR = os.path.abspath(os.path.dirname(__file__))
ADMIN_TOOLS_MEDIA_URL = ROOTDIR + '/media/admin_tools/'
MEDIA_ROOT = ROOTDIR + '/media/admin_tools/'
ADMIN_TOOLS_THEMING_CSS = 'css/theming.css'
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
ADMIN_TOOLS_INDEX_DASHBOARD = 'footprint.dashboard.CustomIndexDashboard'
ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'footprint.dashboard.CustomAppIndexDashboard'
ADMIN_TOOLS_MENU = 'footprint.menu.CustomMenu'
STATIC_ROOT = ROOTDIR + '/fpui/static/'
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
Had the same problem and finally managed to make it work.
I think your INSTALLED_APPS are ordered correctly - the admin_tools should be before django.contrib.admin. To be absolutely sure push django.contrib.admin below other admin_tools apps too.
The problem is probably somewhere in the other configurations; mine was that admin_tools couldn't access my templates and was running the regular admin instead.
Try the below:
ROOTDIR = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(ROOTDIR,'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_ROOT,'media/static')
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
ROOT_URLCONF = 'your_project_name.urls'
TEMPLATE_DIRS = (
os.path.join( PROJECT_ROOT, 'templates' ),
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
)
INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#'grappelli', #for a sweet django admin look
# 'django.contrib.admindocs',
'django_extensions',
'fpui', #the footprint front-end ui app
)
Note that I used realpath for ROOTDIR so that symbolic links may be resolved if there are any. Replace the your_project_name with your project name in ROOT_URLCONF.
Other parameters such as ADMIN_TOOLS_INDEX_DASHBOARD, ADMIN_TOOLS_APP_INDEX_DASHBOARD and ADMIN_TOOLS_APP_INDEX_DASHBOARD are optional, remove them for now so they won't affect the default configuration.
Of course also make sure your urls.py is configured as in the admin_tools guide.
Good luck
Check out the order of your INSTALLED_APPS; It might help if you place the django.contrib.admin just below the django-admin-tools, the order here is used for choosing the right /templates/admin directory.
A little bit late, but I had the same problem, which turned out to be caused by the following circumstance: before installing admin-tools I had overridden one of the admin templates (base-site.html) by putting a modified version in my_project/templates/admin. So it would always use this template instead of the admin_tools one. After removing the custom template it worked.
Related
I'm trying to use Django Compressor, which seems pretty straight-forward, but for some reason I keep getting an error, specifically:
When using Django Compressor together with staticfiles, please add 'compressor.finders.CompressorFinder' to the STATICFILES_FINDERS setting
My settings.py file includes the following:
DEBUG = True
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
'compressor',
)
STATIC_URL = '/static/'
STATICFILES_FINDER = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder'
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, '_static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
COMPRESS_ENABLED = True
I'm not sure if this is a compatibility issue with Django 1.10 (Django Compressor changelog states it is compatible with 1.10), or if Django Compressor simply is broken, since I've clearly added 'compressor.finders.CompressorFinder' to the STATICFILES_FINDERS setting. I've also tried with DEBUG=False.
Any help is appreciated.
In accordance with the django-pipeline docs, I've added 'pipeline.middleware.MinifyHTMLMiddleware', to my MIDDLEWARE_CLASSES to minify html files. But, when I check the htmls that have been rendered while running the server, they are not minified. Can some one please suggest if I am missing anything.
Below are my MIDDLEWARE_CLASSES. I even tried with GZipMiddleware class enabled, but it still does'nt work. I have also tried with both DEBUG = False & DEBUG = True in settings.py with no success.
MIDDLEWARE_CLASSES = (
#'django.middleware.gzip.GZipMiddleware',
'pipeline.middleware.MinifyHTMLMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'Testapp.signin.views.SocialAuthExceptionMiddleware',
)
EDIT: Added Installed Apps and Static files storage settings.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#'django.contrib.admin',
'social.apps.django_app.default',
# 'django.contrib.admindocs',
'Testapp',
'signin',
'pipeline',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
To work pipeline MinifyHTMLMiddleware change DEBUG = False in settings.py
DEBUG = false
Or add in settings.py
PIPELINE_ENABLED = True
i've had the same issue, but I've found the solution. You have to add this Middleware class first:
'htmlmin.middleware.MarkRequestMiddleware',
When you do that it adds to request an attribute
request._hit_htmlmin = True
which is checked then in MinifyHTMLMiddleware class. Now it's working great.
I'm using django-compressor for a project, but when I run the ./manage compress command I got a list of errors like:
Invalid template /home/somepath: 'some_template_tags' is not a valid tag library: ImportError raised loading postman.templatetags.some_template_tags: cannot import name SomeLibrary
I don't have any extra information. Moreover the application is added to INSTALLED_APPS and the template tags runs normally without django-compressor.
Update:
This is the settings.pyfile:
INSTALLED_APPS = (
'django.contrib.staticfiles',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'classytags',
'postman',
# More apps
'compressor',
)
# More lines
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
The problem was postman. I replaced the function: get_user_model() with User on the postman/models.py file:
Static files with Django are driving me insane. I'm successfully able to load my template from the directory specified in TEMPLATE_DIRS, but when I try to load my css and js files from the STATICFILES_DIRS it doesn't work.
Below are the relevant parts of my settings.py file:
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/jrubins/Documents/crowdcluster/crowdcluster/Design/websiteDesign/website/',
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
TEMPLATE_DIRS = (
'/home/jrubins/Documents/crowdcluster/crowdcluster/Design/websiteDesign/website/',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'items'
)
Please let me know if you need more info or if you see something wrong. Thanks in advance.
Looks like I didn't add RequestContext in my render_to_response() in my view. Solved the problem and should have looked closer at the django documentation.
I am having the same problem, but I found this website which has a lot of information that might be able to help
http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
I have stopped creating new project with django 1.1 and from that time was only working on already created applications. Since then I guess that static serving somehow changed (project is using Django 1.2.4). I'm struggling for few hours and with no results, so if somebody knows what I'm doing wrong please let me know.
My settings :
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
SECRET_KEY = '(d9bahjuyy_i-)4b(w9gc5a&s&5jemcn7&b^wrbuemah3p-6^#'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'project',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.request",
"django.core.context_processors.media",
"django.core.context_processors.csrf",
"django.core.context_processors.i18n",
)
urls:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes' : True}),
)
And media files are located in ../project_path/media
In templates I get the {{ MEDIA_URL }} path as /static/ but my files are not loaded. Going to http://127.0.0.1:8000/static/ (with or without last slash) shows root page. Firebug shows the html code of page in place of javascript files. I would rather expect 404 error. Where's the problem ?
Swicthed to 1.3 . Problem remains.
Just in case if you are using render_to_response, you have to pass optional 3rd parameter:
context_instance=RequestContext(request)
soe the full code looks like:
return render_to_response('index.html',{'dict':'ionary'},context_instance=RequestContext(request))
{{ STATIC_URL }} works with RequestContext, while default for render_to_response is Context
If you are using Django's 1.3 django.contrib.staticfiles, the app will look for static files under the static sub-folder of all your installed apps. For instance, staticfiles will automatically pick up the following css:
yourproject/
appone/
static/
sample.css
If you are using django.contrib.staticfiles and STATIC_URL = '/static/' in your settings.py, you can easily access the css at:
http://localhost:8000/static/sample.css
For your case, it looks like you have a static folder under your project folder, I will assume the following:
yourproject/
static/
If you want staticfiles to pick the above, remove the following from urls.py:
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes' : True}),
Add the following to your settings.py:
import os
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'static'),
)
In your template, you might want to start using STATIC_URL instead of MEDIA_URL unless they are both pointing to the same value.
You can read more about staticfiles in Django 1.3.