我想在django模板标签中连接字符串
{% extend shop/shop_name/base.html %}
Run Code Online (Sandbox Code Playgroud)
这里shop_name是我的变量,我想将其与路径的其余部分连接起来.
假设我有shop_name
我希望结果能够扩展 shop_name=example.com
这可能是一个愚蠢的问题,但它并没有点击我的脑袋.
在Django中,惯例是将您的应用程序特有的所有静态文件(即css,js)放入名为static的文件夹中.所以结构看起来像这样:
mysite/
manage.py
mysite/ --> (settings.py, etc)
myapp/ --> (models.py, views.py, etc)
static/
Run Code Online (Sandbox Code Playgroud)
在mysite/settings.py我有:
STATIC_ROOT = 'staticfiles'
Run Code Online (Sandbox Code Playgroud)
所以当我运行命令时:
python manage.py collectstatic
Run Code Online (Sandbox Code Playgroud)
它在根级别创建一个名为staticfiles的文件夹(与myapp /目录相同)
这有什么意义?是不是只创建了我所有静态文件的副本?
我正在ValueError跑步的时候python manage.py test.我的项目已命名fellow_go,我正在开发一个名为的应用程序pickup.
请注意,此错误是在相对较新的Django提交中添加的:已修复#24452 - 修复了嵌套路径的HashedFilesMixin正确性..
======================================================================
ERROR: test_view_url_exists_at_desired_location (pickup.tests.test_view.HomePageViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/sunqingyao/PycharmProjects/fellow_go/pickup/tests/test_view.py", line 10, in test_view_url_exists_at_desired_location
resp = self.client.get('/', follow=True)
File "/Users/sunqingyao/Envs/django_tutorial/lib/python3.6/site-packages/django/test/client.py", line 536, in get
**extra)
File "/Users/sunqingyao/Envs/django_tutorial/lib/python3.6/site-packages/django/test/client.py", line 340, in get
return self.generic('GET', path, secure=secure, **r)
File "/Users/sunqingyao/Envs/django_tutorial/lib/python3.6/site-packages/django/test/client.py", line 416, in generic
return self.request(**r)
File "/Users/sunqingyao/Envs/django_tutorial/lib/python3.6/site-packages/django/test/client.py", line 501, in request
six.reraise(*exc_info)
File "/Users/sunqingyao/Envs/django_tutorial/lib/python3.6/site-packages/django/utils/six.py", line 686, in reraise
raise value
File "/Users/sunqingyao/Envs/django_tutorial/lib/python3.6/site-packages/django/core/handlers/exception.py", line …Run Code Online (Sandbox Code Playgroud) 是我在Django中的第一个应用程序,我正在尝试准备将Django(2.0)应用程序用于生产,但是我无法使用WhiteNoise使静态文件正确加载
我一直一直在日志中遇到下一个错误
ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
ValueError: Missing staticfiles manifest entry for 'css/inicio.css'
[02/Jun/2018 14:40:37] ERROR [django.server:124] "GET /participation/prueba HTTP/1.1" 500 27
Run Code Online (Sandbox Code Playgroud)
我有以下settings.py
...
DEBUG=False
DJANGO_APPS = ['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
#Delete for development whitenoise.runserver_nostatic
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
'django.contrib.sites'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
STATICFILES_DIRS = (
(os.path.join(BASE_DIR, 'static')),
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Run Code Online (Sandbox Code Playgroud)
我在根目录下将所有静态文件都放在一个名为static的文件夹中,当我运行manage.py collectstatic时,我会在staticfiles目录中生成所有静态文件,但是无论如何我还是无法使其运行。
我尝试找出问题所在,并且正在使用以下模板
<!DOCTYPE …Run Code Online (Sandbox Code Playgroud) python django production-environment django-staticfiles whitenoise
在将其标记为重复之前,我已阅读ValueError: Missing staticfiles manifest entry for 'favicon.ico' ,但它并没有解决我的问题。
我有以下模型:
from django.contrib.staticfiles.templatetags.staticfiles import static
class Profile(models.Model):
user = models.ForeignKey(SocialUser, on_delete=models.PROTECT)
avatar_url = models.URLField(
default=static('pledges/images/no-profile-photo.png'))
Run Code Online (Sandbox Code Playgroud)
我正在使用 Codeship for CI,当我运行时:
$ python manage.py collectstatic --noinput
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/rof/.pyenv/versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/rof/.pyenv/versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/home/rof/.pyenv/versions/3.6/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/rof/.pyenv/versions/3.6/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/home/rof/.pyenv/versions/3.6/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models …Run Code Online (Sandbox Code Playgroud)