questions
- The view back_ground.views.article didn’t return an HttpResponse object. It returned None instead.
解决方法:检查路由中是否写了参数url(r’^update_article/(\d+)’, views.update_article)
- 图片上传
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35<!--1. form表单中,有 enctype="multipart/form-data" 这个属性-->
<!--2.图片的路径-->
<p>标题图片:<input type="file" name="icon">{{ form.icon }}
{% if article.icon %}
<img src="/media/{{ article.icon }}" alt="加载失败">
{% endif %}
</p>
<!--3. 解析上传的文件-->
if request.method == 'POST':
form = EditArtForm(request.POST, request.FILES)
if form.is_valid():
# 验证成功
title = form.cleaned_data['title']
desc = form.cleaned_data['desc']
content = form.cleaned_data['content']
icon = form.cleaned_data['icon']
article = Article.objects.filter(pk=id).first()
article.title = title
article.desc = desc
article.content = content
if icon:
article.icon = icon
article.save()
return HttpResponseRedirect(reverse('back_ground:article'))
# 验证失败
article = Article.objects.filter(pk=id).first()
return render(request,
'add_article.html',
{'form': form, 'article': article})
<!--4.setting文件中添加解析文件-->
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
<!--5.主路由urls中,添加保存路径-->
# 告诉django,解析media文件夹中的静态文件
urlpatterns += static(MEDIA_URL, document_root=MEDIA_ROOT)
3.错误:1
2[root@iZhp3c0fe0km5ut9vmr8ooZ home]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
解决方法:uwsgi.txt或者nginx.txt文件中的内容可能有错
4.错误:1
2(env) [root@smile]# pip3 install -r re_install.txt
Could not open requirements file: [Errorn 2] No such file or directory: 're_install.txt'
解释:表示没有文件re_install.txt,所以不能打开