静态文件在生产中不可见| DJANGO

时间:2018-02-15 17:45:02

标签: python django python-2.7 django-1.11

我有点困惑。我在我的项目中使用django-el-pagination应用程序。此应用使用模板中的下一个javascript:

return $query->where(['user_id' => $from, 'to' => $from])->orWhere(['user_id' => $to, 'to' => $to])->get();

在django开发服务器中完美的作品,但在制作中它显示404。

在制作中我安装此应用程序。在我的<script src="{% static 'el-pagination/js/el-pagination.js'%}"></script> 文件下面:

settings.py

我也做了DEBUG = True MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'templates'), ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], }, }, ] STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static_root') 命令。我忘了做什么?

2 个答案:

答案 0 :(得分:2)

来自the documentation

  

在开发过程中,如果你使用django.contrib.staticfiles,这将是   当DEBUG设置为True时,由runserver自动完成(参见   django.contrib.staticfiles.views.serve())。

因此,如果您不使用runserver,并且DEBUG设置为False则不应提供这些文件。

无论如何,如果您也从同一文档中考虑这一点:

  

这种方法效率极低,可能不安全,因此不适合生产。

以下是some suggested ways在生产中提供静态文件,例如,链接的是与反向代理服务器(例如nginx或apache)一起提供。

答案 1 :(得分:-1)

这通常发生在生产服务器上。您可以从生产服务器访问静态文件

<script src="https://techoryze.herokuapp.com/static/js/jquery.js" />

Check the screenshot

相关问题