Django值错误 [英] Django Value Error

查看:36
本文介绍了Django值错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读《与Django探戈》一书.

I am reading the book "Tango with Django".

我试图通过URL访问jpg文件.我收到此错误:

I tried to access a jpg file via URL. I get this error:

File "/home/studpro/.local/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 61, in __init__
prefix, root = root ValueError: need more than 1 value to unpack

我的 settings.py 看起来像这样:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static'), 

# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATICFILES_DIRS = [STATIC_DIR,]

我正在运行Django 1.10.08和Python 2.7.

I am running Django 1.10.08 and Python 2.7.

任何人都有线索可能是什么错误?

Anyone has a clue what could be the mistake?

推荐答案

您在此行上有一个逗号结尾

You have a trailing comma on this line

STATIC_DIR = os.path.join(BASE_DIR, 'static'),
#                                            ^ 

这会导致 STATIC_DIR 是一个元组而不是字符串,然后使 STATICFILES_DIRS 成为元组列表而不是字符串列表.

It causes STATIC_DIRto be a tuple instead of a string, which then makes STATICFILES_DIRS a list of tuples instead of a list of strings.

删除该逗号.

这篇关于Django值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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