search

Home  >  Q&A  >  body text

python - 用uWSGI测试Django项目,找不到static里面的静态文件

运行:

uwsgi --http :8080 --module DDoS.wsgi

然后访问localohsot:8080/ddos/加载不出静态文件

我的项目目录结构:

配置文件STATIC路由:

Django Version == 1.7.6

请问如何解决?谢谢

大家讲道理大家讲道理2802 days ago902

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-18 09:16:15

    I have encountered similar problems before, and the solution is as follows (for reference only):

    urls.py

    from django.conf.urls import include, url
    from django.contrib import admin
    from django.conf.urls.static import static
    from django.conf import settings
    
    urlpatterns = [
                      url(r'^admin/', include(admin.site.urls)),
                  ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

    settings.py

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
                                                                                               
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'backend/static')
    
    MEDIA_URL = '/upload/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'backend/upload')

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:16:15

    settings configure STATIC_URL and STATICFILES_DIRS

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    STATIC_URL = '/static/'
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )

    Write like this on the templates page

    <script src="{{ STATIC_URL }}js/xxx.js"></script>

    reply
    0
  • Cancelreply