Django中URL的相关配置以及后台函数常见设置(Django系列6)

来源:互联网 发布:crossover mac性能如何 编辑:程序博客网 时间:2024/05/20 15:42

博客核心内容:



参考博客:http://www.cnblogs.com/yuanchenqi/articles/6811632.html
样式1:
这里写图片描述
样式2:

<div>    {% for news in news_list %}        <div>{{ news.title }} - {{ news.comment_count }} - <a news_id="{{ news.id }}">赞:{{ news.favor_count }}</a></div>    {% endfor %}</div>

这里写图片描述
到现在为止比较标准的后台逻辑代码:

        url(r'upload/', views.upload),        <!DOCTYPE html>        <html lang="en">        <head>            <meta charset="UTF-8">            <title>Title</title>        </head>        <body>        <form action="/upload/" method="POST" enctype="multipart/form-data">            {% csrf_token %}            <input type="file" name="fffff">            <input type="submit" value="提交">        </form>        </body>        </html>        def upload(request,*args,**kwargs):            if request.method == "GET":                return render(request,'upload.html')            else:                file_obj = request.FILES.get('fffff')                print('文件的名字是:%s' % file_obj.name)                fw = open(file_obj.name,'wb')                for chunk in file_obj.chunks():                    fw.write(chunk)                fw.close()                return render(request,'upload.html')
原创粉丝点击