I've recently adopted this method of serving our static and media files for our docker containers running a wagtail django site.
Serving static and media files from S3 wagtail
I've just realised that I'm going to need to change some things locally in order to be able to serve static files :-(
I don't want to run the collectstatic command for local dev, as that's going to put a load of uneccessary wagtailadmin stuff into the static folder which will then be in the github repo.
Does anyone know how I'd serve the wagtail admin files without running collectstatic?
Related
The website displays to localhost without css, js, or images.
I setup Windows IIS according to this blog including the final section about static files. The methods outlined are similar to answers from this question, this question, this blog, and this youtube video on how to serve static files from django with IIS.
UPDATE: The problem may be coming from my virtual environment. This project was developed with Anaconda. When I followed the listed tutorials I simply used the paths to my conda venv and didn't think anything of it since the localhost loaded without errors. At the time python was only present on my machine in the anaconda environment, so if manage.py was able to execute and database data was accessed and displayed(without css/js) then I presumed this was not an issue. I am currently trying to interpret this blog on how to setup Anaconda for IIS 8.5 to see if I need to make additional changes to IIS 10. I have not had any luck using web.config files and have had to accomplish the same goals through IIS manager. Jalpa Panchal's comment lead me to investigate the environment.
Any ideas on what additional changes need to be made for IIS 10 to interpret an Anaconda(conda 4.8.3) developed django application?
ORIGINAL POST:
Django settings:
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # tested in shell, it is where I expect at the same level as manage.py
The directory "static" was created with manage.py collectstatic in the expected STATIC_ROOT location with all of the static files contained
IIS Manager:
The static directory was then added as a virtual directory:
Then I removed the django handler I created from the static directory's handler mappings:
I unlocked the handlers at the root:
The django application did display properly, with static files, when I tried using Wampserver w/ Apache and mod_wsgi. Unfortunately, it appears windows IIS will be the better solution for other unrelated reasons. Not too mention Wampserver is a development server, not a production server.
I defined a path for the environment variable WSGI_LOG, the logs generated have no errors. Just states wfastcgi.py was initialized and will restart when there are changes to the files in my project
What else can I be missing that would prevent my static files from being processed?
I have a single container docker that consists of my flask-based api and a built react application.
How do I make Beanstalk run my flask app and serve my static react app files through nginx?
I have found various potential solutions, but being completely new to Beanstalk it is difficult for me to understand the implications I choose a path to proceed.
.ebextensions
I assume I can completely rewrite nginx config, but it seems excessive if all I want is to serve some static files?
2. Copy files to nginx folder.
This page describes how to configure a custom docker container and in what nginx folder files should go
3. Tell EB to serve static files through UI or CLI
This discussion covers it. It feels "wrong" going outside docker for getting this to work.
For static directories that are not related to my own app, but to other Django modules (at the project_name/static directory ), do they need to be checked in to version control or do they automatically generate if a Django project is checked out somewhere else?
The project-wide django static directory, $STATIC_ROOT, referenced by settings.py, should be not be in source control. Only the static directory for each app should be in source control.
In development, static files can be served by runserver.
In production, the files are collected from each installed app to the single $STATIC_ROOT via
python manage.py collectstatic
See https://docs.djangoproject.com/en/1.7/howto/static-files/.
So you should put the static directory for any app you develop in source control, but you should treat the static directory for any third-party apps the same as any other directory for those apps. I.e., if you install an app using pip, that will include its static directory if any.
I have a regular django site, with djangorestframework (v2.3.14) serving restful api under "/api". On local box everything works fine (mac / mavericks), on remote box (Ubuntu 12) the API browser comes up but all the bootstrap stuff is missing (the page looks like it's out of 1992 prototype instead of pretty bootstrap theme i see locally).
All the pip dependencies have been upgraded and are identical. Locally running site through PyCharm, remotely it is running on WSGI.
What can I check to see what the issue is and resolve it??
I suppose that under PyCharm on your local machine you are running the development server, which serves static files directly from your apps and projects internal locations.
After every deployment into production (your WSGI server) you need to collect all static files to a single place, your STATIC_ROOT. This is a job for the django management command collectstatic, see Django docs here.
The command may look like this:
# Executing collectstatic (organize static files)
python /path/to/your/project/manage.py collectstatic --noinput
For further details you may also read Django cannot find static files. Need a second pair of eyes, I'm going crazy.
If this question doesn't help, you can quicly fix it making a link under your proyect's static folder
ln -s /your_env_folder/lib/pythonX.X/site-packages/rest_framework/static/rest_framework rest_framework
I'm building a Django app in Python 3.3.1 to be deployed on Heroku. Due to its ephemeral filesystem, Heroku can't serve the app's static files from a local filesystem, so they need to be located elsewhere, and Amazon S3 is where I'd like to put them.
I've found a number of helpful tutorials (Deploying Django on Heroku, among others), all of which make use of the django-storages app and boto to collect the static files and store them on S3. Unfortunately, work on porting boto to Python3 is still incomplete. There are other S3 storage providers that django-storages can work with (Apache Libcloud or the simple Amazon S3 Python library), but django-storages itself doesn't run on Python3, either.
I've also seen hacks that add a collectstatic call to the Heroku app's Procfile, which does put the files somewhere that they can be used by the Django app, but it slows down deployment; the files must be collected and uploaded every time the app deploys. Heroku dynos aren't well-suited to serving static files, anyhow, and I'd eventually like to store user data, as well, which will require a non-Heroku data store like S3.
Is there a Python3-compatible storage backend for Django other than those provided in django-storages? Or am I stuck with Python 2.7 for the time being?
django-storages-redux (now just django-storages) is working for me very nicely in conjunction with boto which now has Python 3 support for its s3 functionality.
django-storages-p3 looks promising. Give it a try and let me know :D.