2017-07-24 60 views
0

因此,我試圖學習django以及嘗試通過mod_wsgi在Apache服務器上創建Angular和Django REST後端的應用程序。目前,我遇到了靜態文件的問題。 Everyhing是確定當應用程序使用Django工具運行在127.0.0.1:8000,但是當我通過Apache加載它 - 我缺少靜,所以輸出看上去很原始:無法加載靜態,Apache上的Django rest_framework,Windows

enter image description here

我試圖收集與靜manage.py collectstatics,試圖定義與蟒蛇迪爾斯靜一個目錄 - 什麼都沒有:

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虛擬主機設置:

<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> 

你能提出一個解決方案嗎?

+0

你的Apache配置是什麼樣的? –

+0

@DanielRoseman更新 – genesi5

+0

好吧,你似乎沒有做任何事情來通過Apache爲你的資產提供服務。 –

回答

0

所以,我只好在虛擬主機設置中添加額外的別名,athe目前它還挺工作:

<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> 
0

你必須按順序使用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> 
申報很多事情在 Apache2.conf

這是Linux的一個例子,但它與Windows一樣;)