Commit ca8d19f6 by liuyingying

资源存储路径

parent 49e5cb4c
...@@ -107,7 +107,7 @@ def save_article(request): ...@@ -107,7 +107,7 @@ def save_article(request):
return JsonResponse({'message': 0, 'error': '文件已存在'}) return JsonResponse({'message': 0, 'error': '文件已存在'})
else: else:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
destination = os.path.join(BASE_DIR, 'hunter', 'static', 'hunter/articles', myfile.name) destination = os.path.join(BASE_DIR, 'static', 'articles', myfile.name)
if os.path.exists(destination): if os.path.exists(destination):
os.remove(destination) os.remove(destination)
with open(destination, 'wb+') as dest: with open(destination, 'wb+') as dest:
......
...@@ -220,49 +220,6 @@ def article_html(request, article_id): ...@@ -220,49 +220,6 @@ def article_html(request, article_id):
# 写文章页面 # 写文章页面
def write_art_html(request): def write_art_html(request):
if request.is_ajax():
userID = request.POST.get('userID', '')
title = request.POST.get('title', '')
content = request.POST.get('content', '')
editdatetime = datetime.datetime.now().date()
is_have_file = request.POST['isHaveFile']
link = ""
# 加入判断题目是否相同
is_have = Articles.objects.filter(title=title).count()
if is_have > 0:
return JsonResponse({'message': 0, 'error': '该题目已存在'})
if int(is_have_file) > 0:
myfile = request.FILES['myfile']
if Articles.objects.filter(attachment=myfile.name).count():
return JsonResponse({'message': 0, 'error': '文件已存在'})
else:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
destination = os.path.join(BASE_DIR, 'hunter', 'static', 'hunter/articles', myfile.name)
if os.path.exists(destination):
os.remove(destination)
with open(destination, 'wb+') as dest:
for chunk in myfile.chunks():
dest.write(chunk)
dest.close()
link = myfile.name
if Articles.objects.last() is None:
articleID = 1
else:
articleID = Articles.objects.last().articleID + 1
try:
authorID = User.objects.get(userID=userID)
except ObjectDoesNotExist as e:
response = JsonResponse({"message": 0, 'error': '用户不存在,请检查是否登录'})
return response
try:
Articles.objects.create(articleID=articleID, authorID=userID, title=title, content=content,
editDateTime=editdatetime,
attachment=link)
response = JsonResponse({"message": 1})
except ProgrammingError as e:
response = JsonResponse({"message": 0, 'error': '数据库错误'})
return response
return response
return render(request, 'write.html') return render(request, 'write.html')
...@@ -277,7 +234,7 @@ def edit_art_html(request, article_id): ...@@ -277,7 +234,7 @@ def edit_art_html(request, article_id):
def uploadImg(request): def uploadImg(request):
file_obj = request.FILES.get("image") file_obj = request.FILES.get("image")
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
file_path = os.path.join(BASE_DIR, 'hunter', 'static', 'articles/images', file_obj.name) file_path = os.path.join(BASE_DIR, 'static', 'articles/images', file_obj.name)
link_path = os.path.join('/static', 'articles/images', file_obj.name) link_path = os.path.join('/static', 'articles/images', file_obj.name)
with open(file_path, 'wb') as f: with open(file_path, 'wb') as f:
for chunk in file_obj.chunks(): for chunk in file_obj.chunks():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment