2017-07-24 26 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一样;)