1

So, i'm trying to learn django as well as trying to make an app with Angular and Django REST backend on Apache server via mod_wsgi. Currently, i got a problem with static files. Everyhing is ok when app runs with Django tools on 127.0.0.1:8000, but when i load it via Apache - i'm missing statics, so output looks very raw:

enter image description here

I tried to collect statics with manage.py collectstatics, tried to define a dir with statics in python dirs - got nothing:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'DjangoApp/static/')

STATICFILES_DIRS = [
    'C:/Users/<user>/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static',
]

Apache virtual host settings:

<VirtualHost 127.0.0.1:8081>
    ##ServerAdmin [email protected]
    WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
    DocumentRoot "D:/genesi5/Coding/www/django"
    ServerName DjangoApp
    ServerAlias DjangoApp
    ErrorLog "logs/myapp/error.log"
    CustomLog "logs/myapp/access.log" common
    <Directory "D:/genesi5/Coding/www/django">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>

httpd.conf:

LoadModule wsgi_module "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"

<IfModule wsgi_module>
    LoadFile "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/python36.dll"
    WSGIPythonHome "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32"
    WSGIPassAuthorization On
</IfModule>

Can you suggest a solution?

6
  • What does your Apache configuration look like? Commented Jul 24, 2017 at 13:24
  • @DanielRoseman updated Commented Jul 24, 2017 at 13:27
  • Well, you don't seem to have done anything to serve your assets via Apache. Commented Jul 24, 2017 at 13:29
  • @DanielRoseman you mean, i need to do this with ProxyPass? Commented Jul 24, 2017 at 13:37
  • Er, no. You need to define an Alias that points to the staticfiles directory. Commented Jul 24, 2017 at 13:46

2 Answers 2

1

So, i had to add extra alias in virtualhost settings, and athe moment it's kinda works:

<VirtualHost 127.0.0.1:8081>
    ##ServerAdmin [email protected]
    WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
    DocumentRoot "D:/genesi5/Coding/www/django"
    ServerName DjangoApp
    ServerAlias DjangoApp
    ErrorLog "logs/myapp/error.log"
    CustomLog "logs/myapp/access.log" common
    Alias /static "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static"
    <Directory "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static">
        Require all Granted
    </Directory>
    <Directory "D:/genesi5/Coding/www/django">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>
Sign up to request clarification or add additional context in comments.

Comments

1

You have to declare lots of things in Apache2.conf in order to use mod_wsgi

WSGIScriptAlias / /path_to_wsgi.py
WSGIPythonPath /path_to_your_project
Alias /static/ /path_to_your_static_directory

<Directory /path_to_your_static_directory>
        Require all granted
</Directory>

<Directory /path_to_your_project_directory>
        <Files wsgi.py>
                #Options Indexes FollowSymLinks
                #Require all granted
                #SetEnvIfNoCase Host .+ VALID_HOST
                Order deny,allow
                Allow from all
                #Allow from env=VALID_HOST
        </Files>
</Directory>

<Directory />
       Options FollowSymLinks
       AllowOverride None
       Require all denied
</Directory>

<Directory /usr/share>
       AllowOverride None
       Require all granted
</Directory>

<Directory /var/www/>
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
</Directory>

<Directory /srv/>
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
</Directory>

It's an example with Linux, but it's the same thing with Windows ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.