在settings.py
中未定义MEDIA_ROOT和MEDIA_URL我的models.py
from django.db import models
class Profile(models.Model):
avatar = models.ImageField(upload_to='avatars')
views.py
from django.shortcuts import render, get_object_or_404
from img.models import Profile
def index(request):
p = get_object_or_404(Profile, pk=1)
return render(request, '1.html', {'p': p})
我认为这不重要,但我的urls.py
from django.conf.urls import patterns, url
from img import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
)
我的模板(img src =“HTML中的avatars / 00.jpeg”
<img src="{{ p.avatar.url }}" />
我的项目树
有必要纠正什么?