Mezzanine Static files not serving from STATIC_ROOT - django

I am new to Mezzanine and not an expert in Django. I am trying to make changes in the default Mezzanine theme. I am doing these steps to override default Mezzanine theme,
python manage.py collectstatic
A new static folder is created which stores all the static files across the project in this folder (STATIC_ROOT). This includes Mezzanine default static files as well from virtualenv/lib/python2.7/site-packages/mezzanine/core/static/
Then I run
python manage.py collecttemplates
A new templates folder is created which stores all the templates across the project in this folder.
Now when I make changes in files from /templates directory I get to see those changes in development server.
but when I make changes in /static directory files I do not see those changes in development server.
to make changes to css files I have to go to
virtualenv/lib/python2.7/site-packages/mezzanine/core/static/ path and then only I can see the changes in development server.
I want to know what am I doing wrong. I do not want to make changes in mezzanine css files, I want to overwrite them form static_root.

In mezzanine and in django sites in general, you should not edit files in the /static folder directly since these will be overwritten each time you use the collectstatic command.
Each of the templates Mezzanine provides can be found in the templates directory of each Django app that Mezzanine is comprised of. E.g the base template in mezzanine/core/templates/base.html.
To edit the templates you’d like to modify, copy them into your project’s templates directory and modify them there. You can also use the collecttemplates command to copy templates over automatically. Run python manage.py collecttemplates --help for more info.
The mezzanine template lookup system is described here. This post may also be useful

OKay, After some research I realized, This is not the way to overwrite templates. You want to copy static folder from Mezzanine package and paste it in an app where you want to use it, then edit that copied files. This is written in documentation for mezzanine, I missed that part.

Related

Django load static in development directly from static folder (Not from apps)

I use django for the backend, in the frontend I use vue.js, so 99% of my CSS it's handled by vue.js, however I need a simple base.css for some customization in the landingpage and few things like this.
Normally in django I would put the file inside app/static/app/base.css then do collectstatic and get it under static/app/ for production.
I would like to avoid to keep it under an app as it's just a file. I'm trying adding a folder under my main "static" folder. But it seems in development django in not fetching it at all, it fetches directly and only static files from apps.
How can I tell django to fetch it directly from the static main folder as it would do in production?
i.e. I want to add a folder called main in my root (where manage.py is) and use only that to store my static files for both production and development, without passing through the single apps.
You can tell Django to look for static files in other directories by using STATICFILES_DIRS settings.
Just add the following code in your settings.py and it should work:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]

Isn't there collectstatic equivalent for django collect media command?

How can I collect media files from different django project applications into one folder to be easier to deploy in production with Nginx/Apache?
No, there isn't a collectstatic equivalent for media files.
Media files are meant to be uploaded by the user as the site runs, so it doesn't make sense to collect them before deployment.

When I reset STATIC_URL to Amazon S3/CloudFront for my production app, Django Admin no longer finds its CSS stylesheet

How do I resolve? I don't want to push a copy of Django Admin's CSS to my static files unless I have to. Is that my only option or ??
Once you move your application to production, in addition to setting DEBUG = False in your settings.py, you also have to run collectstatic and then upload these files to your webserver.
collectstatic will put all the static files that are required for all installed applications, including the django.contrib apps (like the django admin), into the folder you specified as STATIC_ROOT. You should then copy the entire contents of this folder to wherever your STATIC_URL is pointing to.
If you don't do the above, your stylesheets and other assets will not appear correctly.
As you are using S3, the excellent django-extensions package provides a sync_s3 command that will handle synchronizing your bucket for you.
Starting from django 1.6, there is an official list of things you should do before you are ready to deploy; so if you are on the current version of django make sure you visit that page. It is also pointed to in the comments in settings.py.
in Django 1.3 you could set STATIC_URL to the S3 URL and ADMIN_PREFIX to your local server, creating a webserver alias that serves the files
(in Apache for example: Alias /static/admin/ /absolute/path/to/static/admin/)
but AFAIK this is deprecated in Django 1.4 and not possible with Django >= 1.5, since they always will point to {{STATIC_URL}}admin/.
but i don't understand, why wouldn't you upload your admin static!? i strongly suggest to colletstatic all your media to S3 :)
(i don't know if i understood you question correctly, i'll update the answer if not)

How to tell Django staticfiles to not collect user uploaded media directory files?

I have a very simple question which I was not able to find an answer. Using Django staticfiles app, I call the statics collect routine by typing this command line : python manage.py collectstatic.
My problem is that I've several applications serving statics + a media directory containing user-uploaded files. Django copies all the files to the static directory, including media files!
I just would like Django to not copy user-uploaded files to the static directory when I call python manage.py collectstatic. Does anyone have an idea? Tried --ignore option but without success...
Thank you in advance.
That was a problem of django.contrib.staticfiles.finders.DefaultStorageFinder, try removing that from STATICFILES_FINDERS.
So what exactly doesn't work if you use --ignore?
Though the real solution is not to mix user generated content and static files.
If you keep both types separated you can easily put your static files under version control and don't have to deal with excludes on this front as well. And in fact the separation from media (user generated) and static files is the rationale behind staticfiles:
In previous versions of Django, it was common to place static assets
in MEDIA_ROOT along with user-uploaded files, and serve them both at
MEDIA_URL. Part of the purpose of introducing the staticfiles app is
to make it easier to keep static files separate from user-uploaded
files.
The docs on this topic are really comprehensive: https://docs.djangoproject.com/en/dev/howto/static-files/

How do I tweak CSS on the Django 1.2.3 admin media?

I would like to make CSS-only adjustments to the admin interface (on an RHEL box I don't have sysadmin privileges to). To that end, I would like a local version of /media/ to tweak.
http://docs.djangoproject.com/en/dev/howto/static-files/ (but not http://docs.djangoproject.com/en/1.2/howto/static-files/) suggests running a manage.py collectstatic or manage.py findstatic, and my Django 1.2.3 manage.py does not recognize those commands. Adding 'django.contrib.staticfiles' to my INSTALLED_APPS also broke things (not found).
I would like to customize the CSS, and the way I envision doing that is by getting a private copy of the media for Django's admin and changing from there. What are my best options for a Django 1.2.3 installation?
Just go to your django installation directory, browser to django->contrib-> admin-> directory and copy paste the media folder to your django projects media directory.
Let us say you have your media in project/media which is statically rendered to web as /media/. If you copy your admin media in project/media your admin media web url would be /media/admin/ hence in your settings.py file: ADMIN_MEDIA_PREFIX = '/media/admin/'
You may then modify your css in media directory as you wish to change the look of admin site.
I found a way to do it:
1: Download a fresh copy of Django and unpack it. Under the Django-x.x.x directory was a media directory.
2: Tar/transfer/untar the media directory on my target machine.
3: Change the CSS as needed.
4: When calling python manage.py runserver, add a flag of --adminmedia=./media .