From 37137ce7589e04cc3e771270337aca375c6c3100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A6=E4=BA=AE=E4=BA=AE?= Date: Thu, 12 Jan 2017 22:24:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8A=E4=BC=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DjangoBlog/settings.py | 2 +- blog/views.py | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/DjangoBlog/settings.py b/DjangoBlog/settings.py index d527761..a7b54f5 100644 --- a/DjangoBlog/settings.py +++ b/DjangoBlog/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = '&3g0bdza#c%dm1lf%5gi&0-*53p3t0m*hmcvo29cn^$ji7je(c' DEBUG = True # ALLOWED_HOSTS = [] -ALLOWED_HOSTS = ['blog.lylinux.org', '127.0.0.1'] +ALLOWED_HOSTS = ['www.lylinux.net', '127.0.0.1'] # Application definition INSTALLED_APPS = [ diff --git a/blog/views.py b/blog/views.py index 4e42fb0..66827f9 100644 --- a/blog/views.py +++ b/blog/views.py @@ -17,6 +17,9 @@ from django.http import HttpResponse from abc import ABCMeta, abstractmethod from haystack.generic_views import SearchView from blog.forms import BlogSearchForm +import datetime +from django.views.decorators.csrf import csrf_exempt +import os """ class SeoProcessor(): @@ -200,6 +203,25 @@ class TagDetailView(ArticleListView): return super(TagDetailView, self).get_context_data(**kwargs) +@csrf_exempt +def fileupload(request): + if request.method == 'POST': + fname = '' + timestr = datetime.datetime.now().strftime('%Y/%m/%d') + basepath = os.path.join(r'/var/www/resource/image/', timestr) + if not os.path.exists(basepath): + os.makedirs(basepath) + for filename, file in request.FILES.iteritems(): + fname = filename + savepath = os.path.join(basepath, filename) + with open(savepath, 'wb+') as wfile: + for chunk in file.chunks(): + wfile.write(chunk) + return HttpResponse('https://resource.lylinux.net/' + 'image/' + timestr + '/' + fname) + + else: + return HttpResponse("only for post") + """ class BlogSearchView(SearchView): @@ -223,4 +245,4 @@ class BlogSearchView(SearchView): kwargs['page_type'] = 'search' kwargs['tag_name'] = tag_name return super(BlogSearchView, self).get_context_data(**kwargs) -""" \ No newline at end of file +"""