добрый день.
в модели пишу:
class TextNote(models.Model):
title = models.CharField(max_length=1000, blank = True)
image = models.ImageField(upload_to=os.path.join(PROJECT_PATH, "media"), null=True, blank=True)
в form.py
class TextNoteForm(forms.Form):
title = forms.CharField(max_length=1000)
image = forms.ImageField(required=False)
в views.py
def textnoteadd(request):
if request.method == 'POST':
form = TextNoteForm(request.POST)
if form.is_valid():
note = TextNote()
note.title = form.cleaned_data.get('title')
note.image = form.cleaned_data.get('image', None)
в шаблоне:
{{ view.image.url }}
почему изображение не загружается и не выводится?
ValueError at /notes/15/
The 'image' attribute has no file associated with it.
Request Method: GET
Request URL: http://127.0.0.1:8000/notes/15/
Django Version: 1.4.2
Exception Type: ValueError
Exception Value:
The 'image' attribute has no file associated with it.
Exception Location: /home/webdish/.virtualenvs/testproject/lib/python2.6/site-packages/django/db/models/fields/files.py in _require_file, line 41