Since it did not work on the first time, I created a fresh new venv for my django project.
my folder structure looks like this: btw I used the Django/Apache Setup guide from digitalOcean (https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-16-04)
/home/pi/myproject/myprojectenv (this is where my env is located) /home/pi/myproject/myprojectenv/myproject/myproject (this is where the settings.py is located)
I added this to the settings.py file (I use a pi, I only serve locally)
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
and at the bottom
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
my /etc/apache2/sites-available/000-default.conf looks like this:
<VirtualHost *:80>
#for django
Alias /static /home/pi/myproject/myprojectenv/myproject
<Directory /home/pi/myproject/myprojectenv/myproject/static>
Require all granted
</Directory>
<Directory /home/pi/myproject/myprojectenv/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/home/pi/myproject/myprojectenv python-path=/home/pi/myproject
WSGIProcessGroup myproject
WSGIScriptAlias / /home/pi/myproject/myprojectenv/myproject/myproject/wsgi.py
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
when I go to /static in the browser I get a http 403 forbidden Error. What am I doing wrong?
CodePudding user response:
Your alias is wrong
Alias /static/ /home/pi/myproject/myprojectenv/myproject/static/
CodePudding user response:
First, I'd remove (if you haven't already) the DocumentRoot from your configuration, since you don't seem to be using that feature. See here.
Where are your static files? If they're in BASE_DIR/static/
, your alias is wrong, as Mohamed has pointed out. And remember to include the last forward slash, so use /static/
instead of /static
.
Also, if you have a static file, let's say BASE_DIR/static/css/styles.css
, you would access this through http://localhost/static/css/styles.css
, so make sure you're using the appropriate URL.
Last but not least, is your site working properly besides apache not serving static files?