添加上传功能

pull/12/head
车亮亮 9 years ago
parent fcd6219abd
commit 37137ce758

@ -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 = [

@ -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)
"""
"""

Loading…
Cancel
Save