MEDIA_ROOT 出现问题 [英] Trouble with MEDIA_ROOT

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

问题描述

我已经完成了关于 django-project 的初学者教程,现在我正在尝试更进一步.所以,我想添加一种将图像添加到民意调查的功能.为此,我需要将 'django.template.context_processors.media' 添加到 context_prosessors 并创建 MEDIA_ROOT.所以我做到了

I've finished a beginner's tutorial on django-project and now I am trying to go further. So, I want to add an ability to add images to polls. To do that, I need to add 'django.template.context_processors.media' to context_prosessors and create MEDIA_ROOT. So i did

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(str(BASE_DIR))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, MEDIA_URL)
print(str(MEDIA_ROOT))

但是当我运行 django-server 时,我看到打印功能的以下结果:

But when I run the django-server I see the following results of the print functions:

我做错了什么?为什么我会看到两次打印功能的结果?

What am I doing wrong? And why do I see the results of the print functions twice?

推荐答案

更改:

MEDIA_URL = '/media/'

致:

MEDIA_URL = 'media/'

<小时>

研究这个例子以了解发生了什么:


Study this example to know what is happening:

import os

print(os.path.join('a', 'b/'))    # prints "a/b/"
print(os.path.join('a', '/b/'))   # prints "/b/"

这篇关于MEDIA_ROOT 出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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