staticfiles和STATIC_URL与virrtualenv - django [英] staticfiles and STATIC_URL with virrtualenv - django

查看:127
本文介绍了staticfiles和STATIC_URL与virrtualenv - django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用virtualenv,我无法获取静态文件在我的django上工作,

I'm using virtualenv and I can't get staticfiles to work on my django,

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    '/home/brian/Projects/RaffleFish/static',

)

我的virtualenv目录是virt_env / virtFish

My virtualenv directory is virt_env/virtFish

如何让我的静态文件工作?我添加virtenv的目录结构

How do I get my staticfiles to work? do I add the directory structure of virtenv

推荐答案

在Django项目中的各个应用程序内,您可以创建一个 static 目录,并在该目录中放置静态文件。这些文件将自动由您的settings.py文件中的INSTALLED_APPS元组中的 django.contrib.staticfiles 模块来处理。这些文件将在开发过程中由 python manage.py runserver 命令自动进行汇总和提供。

Inside the individual applications within your Django project you can create a static directory and place static files within that directory. Those files will automatically be handled by the django.contrib.staticfiles module which should be in the INSTALLED_APPS tuple in your settings.py file. These files will be aggregated and served during the development process automatically by the python manage.py runserver command.

您必须牢记的这个过程的一个窍门是,当部署到生产环境或您不通过 manage.py 提供内容的任何环境的时候,您将必须自己执行这个聚合。 manage.py 命令有一个命令来帮助这个。作为部署的一部分,您应该包含以下命令:

The trick to this process that you must keep in mind is that when it comes time to deploy to production, or any environment where you aren't serving content with manage.py you will have to perform that aggregation yourself. The manage.py command has a command to help with this. As a part of your deploy you should include the command:

python manage.py collectstatic

这将从您的应用程序中的 static 目录中收集(汇总)所有静态文件通过 STATIC_ROOT 设置在 settings.py 中定义的单个位置。

This will collect (aggregate) all the static files from the static directories in your apps into a single location defined in settings.py by the STATIC_ROOT setting.

这篇关于staticfiles和STATIC_URL与virrtualenv - django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆