Deploying static files for a Wagtail application on Divio - python

I'm struggling to understand how I can implement my static files live. This is my first project I'm trying to deploy so it's possible I've missed something, and I'm finding it hard to understand which documentation is best to follow here - Wagtail, Divio or Django?
I can view my website with the localhost fine, the static files are read. But when deploying to Divio’s test servers, no longer, just Bootstrap stylings. Am i meant to set debug to False somewhere, and if so where do I set it so?
The dockerfile in the Divio project contains this command, which I sense is related to deploying live:
# <STATIC>
RUN DJANGO_MODE=build python manage.py collectstatic --noinput
# </STATIC>
What are the steps needed to transition from operating on the localhost and viewing my static correctly, to having it display in test/live deployments?
I thought I could link them with the settings.py file but when I try to do this I experience a problem related to the following step:
Step 7/7 : RUN DJANGO MODE=build python manage.py collectstatic —noinput
It seems to hang almost indefinitely, failing after a long time - the following are the last few lines of my logs.
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/opensans-regular.woff'
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/wagtail.svg'
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/robotoslab-regular.woff'
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/opensans-semibold.woff'
Thanks all in advance for your time and help!

In a Divio Cloud project, the settings for things like static files handling and DEBUG are managed automatically according to the server environment (Live, Test or Local).
See the table in How to run a local project in live configuration. You can override these manually if you need to, but there is no need whatsoever in normal use.
If you have added settings related to static file handling to your settings.py, try commenting them out - almost certainly, it will just work.

Related

Django: unable to locate static files folder

I am trying to setup an AS2 server using the python package django-pyas2 (https://github.com/abhishek-ram/django-pyas2)
Everything has been working fine while I was using the runserver command, but when trying to host my web app using IIS(10), I've noticed that none of my static files get loaded when loading a page.
I've been on countless forums/documentations and I know that I need to setup my IIS to serve these files, but I haven't been able to answer a rather stupid question:
Where is the /static/ folder of django-pyas2 located ???
There is no such folder on the github page.
When using the runserver command, django somehow manages to find all the static files (.css, .js, .png) from the static folder, but I am still totally clueless to where that folder is actually stored.
I've been searching in these locations to no avail: (I'm using a virtual env on Windows Server 2016)
my own project
my venv's site-packages\django-pyas2 folder
in C:\Python37\Lib\site-packages\django-pyas2
in C:\User\AppData\Roaming\Python\Python37\Lib\site-packages\django-pyas2
I've also tried to use the command collectstatic, but I first need to know where the actual /static/ folder is stored.
I've double-checked, and the files are apparently stored locally and not on a CDN. This is driving me kind of nuts, and I could definetly use some help from someone!
A big thanks in advance ❤
EDIT:
my IIS wfastcgi configuration
my IIS advanced settings
I'm not sure about how IIS(10) works but this is usually the fix.
go to settings.py and add a path for your static files.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')#new
Next on the console (command prompt/ terminal/shell) run
python manage.py collectstatic
This should work
OK, so I finally found the static folder I was looking for in this location:
<PYTHON_PATH>\Lib\site-packages\django\contrib\admin\static
I believe the django_pyas2 package is using some default js/css already included with Django, and I couldn't find it because it was burried in Django's files.
For those encountering the same problem, here are the steps I then took to make it work with IIS(10):
copy/pasted the static folder from the django package to my project's root
went to IIS manager, right clicked on my website > Add Application
for the application alias: "static", for the path: <path_to_static_folder>
/!\ IMPORTANT /!\ left clicked on newly created "static" application, went to Mapping Manager, and then deleted the associated FastCGIModule
Didn't have to do anything in settings.py, nor execute the collectstatic command.
Works fine after that!
Thanks for trying to help.

Restarting Python to show changes

I am new to the python script. How do you restart a python script with Django through SSH?
I believe that you project is django based.
Django framework has a project directory, where static files are initially placed. And when you run your project for development purposes, django takes all static from the project static directory.
But for the production django deployment usually get runned command manage.py collectstatic to copy all static into another place. And sometimes there are another command - compress. To compress that static.
This is done to make webserver (apache or ngingx) respond static files without asking django process requests like "five me that static file" and gives ability to cache static files. And it speed-up all work.
So, if you serveer is setted up to take static files from static dir (looks like DOMAIN/public/static/main/ is the static dir) it will have no idea about changes in the project dir (looks like DOMAIN/project_book/main/static/main/ is a project dir).
But I agree with #Sause, looks like you have to be very carefull and have exact understanding of what you're doing with killing any process on the production server.
I think it could be useful for you to read Django documentation about static files too. https://docs.djangoproject.com/en/1.9/howto/static-files/
running pkill python in the ssh works.

Django - Apply changes in HTML & Static files without restarting dev server

I am working in a dev environment using the built in Django web server. One of the inconvenience that I have is everytime I make changes in HTML or Static files it does not apply when I reload the browser until I kill the dev server and run again.
python manage.py runserver localhost:8000
Is there a way so Django will reflect the changes instantly? Thanks in advance
Django reload the server only on changes on .py files. I read different ways to trigger reloading (such as installing a third party app, tweaking caching depending on whether DEBUG = True, etc etc).
The easiest and dumbest way is to make an insignificant slight change in the view you're working on (say, adding a #, removing it) after you edited and saved your template. It is dumb but it works.

Web.py reload development server while code was changed

i'm working on web.py project with separated code in different files
- urls.py for urls,
- views.py for controllers,
- server.py for describing my application and it's option.
But i got a big problem - i need to restart my server (python server.py) every time when code was changed.
it makes me crazy.
I've tried 'touch server.py' and all other project files, tried to remove all *.pyc from project but without restart server code not updated.
May be someone knows how to fix this and save time?
Thanks!
http://webpy.org/docs/0.3/tutorial#developing states:
web.py also has a few tools to help us with debugging. When running with the built-in webserver, it starts the application in debug mode. In debug mode any changes to code and templates are automatically reloaded and error messages will have more helpful information.
The debug is not enabled when the application is run in a real webserver. If you want to disable the debug mode, you can do so by adding the following line before creating your application/templates.
web.config.debug = False
Are you using the internal webserver or an external one?

Django runserver, and s3boto backend

Django's "manage.py runserver" has the wonderful ability to magically gather altered CSS, JS, and image files as it's running. This makes the save changes-reload cycle incredibly fast when doing front-end development (css especially). It's wonderful.
However, we've moved to Heroku recently, and installed django-storages with s3boto to handle static files. It works wonderfully too. However, "manage.py runserver" is no longer automatically showing us updated files. We have to run "manage.py collectstatic" to do so -- that works, but it adds an extra step, and slows down development while we wait for the collectstatic step to upload files to S3.
Is there any way to get the old behavior of runserver back, while keeping django-storages?

Categories