60%为Django开发内容
view.py
from django.shortcuts import render , HttpResponse
from day6 import settings
import os
# Create your views here.
def getfile(request):
if request.method == 'GET':
return render(request , 'get_file.html')
# 获取到file的对象
file = request.FILES.get('file')
# 获取到文件名
name = file.name
# 文件的保存路径
file_dir = os.path.join(settings.BASE_DIR , 'templates' , name)
# 读取浏览器上传的文件
with open(file_dir , 'wb') as f:
# 读取文件对象中的内容需要使用循环读取
for data in file:
f.write(data)
return HttpResponse('ok')
urls.py
from django.urls import path
from app02 import views
urlpatterns = [
path('file/' , views.getfile),
]
40%为Bootstrap开发内容
首页
首页
注册
登录
{% block head %}
首页
欢迎光临
{% endblock head %}
{% block name %}
{% endblock name %}
点击空白处退出提示












评论