我坚持因的 常绿 问题,静态文件没有送达.相反,放置在MEDIA_ROOT子树中的文件可以正确地提供MEDIA_URL.
剥离settings.py:
DEBUG = True
STATIC_URL = '/static/'
STATIC_ROOT = '/home/foo/devel/static'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/foo/devel/media'
# the following is deprecated but is it seems grappelly requires it
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"
STATIC_FILES = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
Run Code Online (Sandbox Code Playgroud)
为了创建我做的项目:
$ cd /home/foo/devel/
$ virtualenv testdrive
$ . bin/activate; pip install django; cd testdrive
$ django-admin.py fbtest
Run Code Online (Sandbox Code Playgroud)
并获得此目录树(剥离):
. <-- /home/foo/devel/
??? bin
??? fbtest
? …Run Code Online (Sandbox Code Playgroud) 我可能只是累了,并没有注意到这里明显的东西,但升级到Django 1.5后,我的静态文件的路径被打破.
settings.py
from os.path import abspath, basename, dirname, join, normpath
SITE_ROOT = dirname(dirname(abspath(__file__)))
SITE_NAME = basename(SITE_ROOT)
PROJECT_ROOT = dirname(SITE_ROOT)
STATIC_ROOT = normpath(join(SITE_ROOT, 'static', 'site_media'))
STATIC_URL = "/site_media/static/"
STATICFILES_FINDERS = (
"staticfiles.finders.FileSystemFinder",
"staticfiles.finders.AppDirectoriesFinder",
"staticfiles.finders.LegacyAppDirectoriesFinder",
"compressor.finders.CompressorFinder",
Run Code Online (Sandbox Code Playgroud)
)
的index.html
<link rel="stylesheet" href="{{ STATIC_URL }}css/site_base.css" />
Run Code Online (Sandbox Code Playgroud) 是否可以仅在 PROJECT_DIR/static 目录中包含静态文件,而在应用程序目录中没有静态文件的重复项,并且不需要执行collectstatic 命令?在本地计算机上使用 Django 开发服务器,在生产中使用其他一些 Web 服务器。从我到目前为止所读到的内容来看,我认为这是不可能的,但也许这不是真的。
我以前做过教程的第一部分,卡住了,意识到有几个版本的教程,删除了民意调查和mysite目录并重新开始.但是,当我跑
$ python manage.py sql轮询结果是:
c:\Python27\Scripts\mysite>python manage.py sql polls
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280,
in execute
translation.activate('en-us')
File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", lin
e 130, in activate
return _trans.activate(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 188, in activate
_active.value = translation(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 django 的开发环境中加载静态文件。我的设置如下所示:
STATIC_ROOT = '/MyProject/myapp/static/'
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
)
Run Code Online (Sandbox Code Playgroud)
我的网站 urls.py 看起来像:
from django.conf import settings
import views
from django.conf.urls.static import static
admin.autodiscover()
urlpatterns = patterns('',
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Run Code Online (Sandbox Code Playgroud)
我的 header-include.html 看起来像:
<link href="{% static 'css/mycss.css' %}" media="screen" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)
我的 css 主管位于:
我的站点 > 静态 > css
我收到错误:
本地主机/静态/css/mycss.css 404(未找到)
我究竟做错了什么???
我正在使用 django 1.6
在我的设置中有这个,效果很好,
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
Run Code Online (Sandbox Code Playgroud)
但当我添加:`MEDIA_ROOT = os.path.join(BASE_DIR, 'media/'),
渲染模板时出现错误:
'tuple' does not support the buffer interface
Run Code Online (Sandbox Code Playgroud)
问题代码: <link href=" {% static 'bootstrap/css/bootstrap.min.css' %} " rel="stylesheet">
这两种设置之间是否存在某种冲突?我想做的就是为用户上传的文件提供服务,我应该将upload_to设置更改为静态目录吗?
有谁以前经历过这个或知道可能是什么问题
感谢任何帮助,谢谢
我正在尝试将我的Django项目推送到Heroku,但它没有加载静态文件.
我用它来设置东西,一切都很好,但我无法解决静态文件的问题.
我的目录结构是这样的
help_the_needy
help_the_needy
__init__.py
settings.py
urls.py
views.py
wsgi.py
manage.py
Procfile
requirements.txt
static
css
font-awesome
fonts
img
js
templates
base.html
display_list2.html
index.html
Run Code Online (Sandbox Code Playgroud)
这是完整的代码(所有文件).
这是我的settings.py.
我尝试了很多东西来解决这个问题,但似乎没有任何工作.
当我按下它时会复制静态文件,但它不会加载它们.
有人可以指出我的错误吗?哪里错了?
我正在尝试使用django中的静态文件.
我看了很多视频,我知道我觉得我做得很好.
以下是settings.py片段:
STATIC_URL = '/static/'
STATICFILES_DIR = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn')
Run Code Online (Sandbox Code Playgroud)
我还将此添加到urls.py:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Run Code Online (Sandbox Code Playgroud)
当我执行collectstatic时,它会复制admin文件夹中的所有内容.但它不是.css从静态文件夹复制我的文件.有人能告诉我我做错了吗?
在将其标记为重复之前,我已阅读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) 我必须使用uwsgi, django, nginx 一切进行项目设置,似乎一切正常,但不知何故,我一直在获取错误,因为static files我一直在在线阅读并尝试了所有可能的方法,但我一直permission denied在我的静态文件夹中收到此错误。
有人可以让我知道我在权限上做错了什么以及我应该如何更改它吗?
这是我的 /var/log/nginx/error.log
open() "/root/project/static/*.css" failed (13: Permission denied), client: 2xx.xx.xx.xxx, server: _, request: "GET /static/*.css HTTP/1.1", host: "1xx.xx.xx.xxx"
这是我的 nginx site-available config
server {
listen 80 default_server;
listen [::]:80 default_server;
# root /var/www/html;
# Add index.php to the list if you are using PHP
# index index.html index.htm index.nginx-debian.html;
server_name _;
#location = /favicon.ico { access_log off; log_not_found off; }
#location /media {
# root /root/project/mediafiles;
#}
location …Run Code Online (Sandbox Code Playgroud) django ×10
python ×4
django-media ×1
heroku ×1
nginx ×1
permissions ×1
sqlite ×1
static-files ×1
ubuntu ×1