I'm trying to move a Django site I have been working on out of the dev server stage and into a real hosting environment. For the time being, I'm just hosting on my personal machine. I already have Apache and mod-wsgi installed, but I'm having issues getting static files up. I'm pretty sure it has to do with Apache. Here is my config file for the site:
<VirtualHost *:80> ServerName localhost ServerAlias daifotis.dyndns.org ServerAdmin [email protected] DocumentRoot /home/daifotis/code/ Alias /media/ /home/daifotis/code/feris/sitestatic Alias /static/ /home/daifotis/code/feris/sitestatic #AliasMatch ^/([^/]*\.css) /home/daifotis/code/feris/sitestatic/$1 <Directory /home/daifotis/code/feris/sitestatic> Order allow,deny Allow from all </Directory> <Directory /home/daifotis/code/feris> Order allow,deny Allow from all </Directory> <Directory /home/daifotis/code/feris/jobsite> Order allow,deny Allow from all </Directory> WSGIDaemonProcess feris processes=2 threads=15 display-name=%{GROUP} WSGIProcessGroup feris WSGIScriptAlias / /home/daifotis/code/feris/apache/django.wsgi <Directory /home/daifotis/code/feris/apache> Order allow,deny Allow from all </Directory> </VirtualHost>
I'm trying to host the files from the directory I alias with static. When I try to load the site, all the content comes up but no css. Also, when I hit my url www.server.com/static/, the page displays with the proper content of the directory. What I don't understand though, is why if I click on a link to view a file, it says that URL does not exist. I've been stuck on this for awhile so any help would be much appreciated.
Django will work with any version of Apache which supports mod_wsgi. The official mod_wsgi documentation is your source for all the details about how to use mod_wsgi. You'll probably want to start with the installation and configuration documentation.
Django provides django. contrib. staticfiles to help you collect static files from each of your applications (and any other places you specify) into a single location that can easily be served in production. STATIC_ROOT is the path that defines where your static files will be collected.
Deploy static view files without installing Magento To do this, take the following steps: Run bin/magento app:config:dump to export the configuration from your production system. Copy the exported files to the non-production code base. Run bin/magento setup:static-content:deploy .
It's possible that you'll need to run the management command python manage.py collectstatic to collect all your application static files into a directory ready to be served by apache. See my answer here regarding settings for using django.contrib.staticfiles.
At the bottom of the file, we will set Django’s STATIC_ROOT. Django can collect and output all static assets into a known directory so that the web server can serve them directly. We’ll use a bit of Python to tell it to use a directory called “static” in our project’s main directory:
Generally if you'd like to use your Django project to present a User Interface (UI) then you'll need to display Images and CSS and serve Javascript files. These are known as static files and to deliver them using Zappa is unlike the traditional method of hosting the static files on a Linux or Windows box.
To start, let’s configure the static files. We will use an alias to tell Apache to map any requests starting with /static to the “static” directory within our project folder. We collected the static assets there earlier. We will set up the alias and then grant access to the directory in question with a directory block:
Figured it out. I had an apache config error on this line:
Alias /static/ /home/daifotis/code/feris/sitestatic
I should have written static without the trailing slash. With the trailing slash Apache will not expand the URL path.
Alias /static /home/daifotis/code/feris/sitestatic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With