How do you setup admin media in Webfaction for Django? - django

I have my django setup. Now i just need to get the admin site to be correct. Currently there is no css asigned to it, so i guese my admin media urls etc in settings file is not correct?
Thanks

Have you read through their docs? Or is there something in there that wasn't working?
This seems more like a question to ask on their forum. Their tech people usually respond pretty quickly.

you need to issue
pythonX.Y manage.py collectstatic
where X.Y is the version of your application's python. this will copy admin media inside your static directory.

Related

Django Admin Styling corrupted

I recently made some changes to my django site, one big one being upgrading from Django 2.2 to 3.1. Now my admin site styling is all messed up. I can't figure out what went wrong or how to fix. Any pointers would be appreciated!
See image of what it looks like after update....
The main home page for admin looks fine, but when I click on one of the models to view, the formatted is definitely not correct.
Also, some not all, of my images on the site are saying 404 not found...
It looks like your browser is caching the CSS / JS from the old version, you can clear your cache and reload. In chrome use ctrl + shift + r to reload.
I was facing the same problem, First I thought it was a Cache issue but it wasn't.
I checked the page source and found a css file being applied to the page which wasn't even present on my drive.
In my case the file was:
static/admin/css/nav_sidebar.css
So I created new file in static/admin/css named nav_sidebar.css,
then copy pasted the code which I got from page source and
added "display:none;" in the #nav-sidebar section(line:34) and [dir="rtl"] #nav-sidebar section(line:45 in my case).
You can find the Original code here by using Google Chrome's inspect tool.
Where to find the code
I had the same issue after bumping django from v3.0 to v3.1. I run python manage.py collectstatic to update css which solved my issue
I was experiencing the same styling as the OP's screenshots.
I had upgraded incrementally from 2.2 -> 3.0 -> 3.1 -> 3.2. I only experienced the styling issues in 3.2
The issue was that there were legacy admin styles committed to the repo in the static folder. To resolve, all I did was delete the committed admin styles, and Django then appeared to use its own styling
I was upgrading from 3.0 to 3.2 and I tried a couple of the answers here without luck. At the end, the following procedure solved it for me:
manually delete the content of the directory STATIC_ROOT (see in settings.py what you named the folder)
run the command python manage.py collectstatic This will repopulate the directory with the newst files
hard refresh your page (ctrl + F5)
I think the other answers here are necessary, but I'll add one more: You might have to bust caches in your server itself. In our example, nginx was configured to provide really long caches to our static files, so we just had to reset it to make changes come through.
Ok maybe I am late to the party but it may help others,
What works for me is:
Set STATIC_ROOT in settings.py (I guess it should be already there as project is old one)
Comment STATIC_DIR in STATICFILES_DIRS list (otherwise it will give error) and run python manage.py collectstatic
Clear browser cache.

django admin django.contrib.staticfiles

I'm following the tutorial contained here:
http://www.djangobook.com/en/2.0/chapter06.html
They say that the admin site should look like this:
http://www.djangobook.com/en/2.0/_images/admin_index.png
When I start the admin site, though, it looks really simplistic, just plain text and links:
Django administration
Welcome, admin. Change password / Log out
Site administration
Auth
Groups Add Change
Users Add Change
Recent Actions
My Actions
None available
I noticed that it looks all nice like the link when I uncomment django.contrib.staticfiles from the INSTALLED_APPS, although that wasn't mentioned in the tutorial...can someone please explain this behavior to me?
Thank you for your help!
The Django Book is a little out of date (although an update is in the works I believe):
This book was originally published by Apress in 2009, and covered Django 1.0. Since then, it’s languished. We’re working on getting the book updated to cover Django 1.4, 1.5, and beyond
Static files are all the CSS/JS & images that your site (and the django admin) uses. They need to be collected and placed somewhere that your server (or development server) can serve them. This is the job of django.contib.staticfiles.
You can read more about this in the 'Managing Static Files' documentation
Websites generally need to serve additional files such as images, JavaScript, or CSS. In Django, we refer to these files as “static files”. Django provides django.contrib.staticfiles to help you manage them.

django: default template file path?

Somebody told me all django apps automatically look within the root apps directory for a 'templates' dir first before looking within settings.TEMPATE_DIRS. However, this didn't work for me.
Is this not true?
I'm on django 1.3.1.
edit:
It turns out, the reason why it wasn't working inside my app's url mapping, I use a view from django.contrib.auth.views.login so it was looking inside the app dir for auth. A possible solution is to inherit login, but is there a better way to resolve this so django will look inside my app dir?
It's the other way around. By default Django first looks in settings.TEMPLATE_DIRS, and the in app folders. This can be customized by settings.TEMPLATE_LOADERS. which default to :
('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader')
Details here: https://docs.djangoproject.com/en/1.4/ref/templates/api/#loader-types
But why would you want to do this?

How to relocate the django admin site below root?

The contrib admin site of Django is a perfect starting point for simple in-house applications that lots of people use.
I've done a bit of searching and seen the discussions of media and tools for working with and merging static media for the admin site. But it is still pretty fragmented and opaque.
Assume I have a site "mysite" with an application "myapp" that is derived from the admin app.
I would really appreciate an example of relocating mysite and myapp, including the admin app, onto a web server where it is not at the root url.
I think this use case would flush out a lot of the issues and confusion that I see people have.
I think what you want to do is use the FORCE_SCRIPT_NAME = '/path/not/at/root/of/domain' option in your settings.py file. No trailing /.
http://docs.djangoproject.com/en/1.3/ref/settings/#force-script-name
I hope I'm understanding your question right and I hope this helps solve it.
Edit: oops gave link to old docs...updated with new docs version
Edit2: Here is another link describing this here at djangoproject again.

Django's admin pages are missing their typical formatting/style, have I set it up wrong?

I finally got my django install working, however I'm noticing that the typical look and feel of the admin pages are missing, and it's as if there are no styles applied to the structure of the pages. Do I have some kind of setup issue or pathing issue that's preventing the style sheets from being found? Where are they stored? My pages look like they are from 1994.
Sounds like your admin media isn't being served correctly. In your settings.py, there's a variable called ADMIN_MEDIA_PREFIX, which specifies the URL where Django should look for them. The actual media files are in "[path to your Python site-packages]/django/contrib/admin/media". When using manage.py runserver, the files are served "automagically". However, when using Apache/nginx/etc it's your responsibility to make sure that your server makes the files available at that URL (using rewrite rules, symlinks, etc). More info can be found here.
I've solved this issue simply with the alias on apache:
Alias /static/admin/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/
Alias admin/media/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/
You need to provide more info for use to help you properly. However, this is most probably because didn't set up your Web server to serve static file, and therefor, the admin CSS is not loaded.
To solve this, got the the admin and look at the HTML source. You'll css the path to the admind css. Make your web server service this file on this path.