diff --git a/README.md b/README.md index d8cf194..dd6b6bd 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ # django-mdeditor -[![ENV](https://img.shields.io/badge/release-v0.1.16-blue.svg)](https://github.com/pylixm/django-mdeditor) -[![ENV](https://img.shields.io/badge/中文-v0.1.16-blue.svg)](./README_CN.md) -[![ENV](https://img.shields.io/badge/Gitter-v0.1.16-blue.svg)](https://gitter.im/django-mdeditor/Lobby) +[![ENV](https://img.shields.io/badge/release-v0.1.17-blue.svg)](https://github.com/pylixm/django-mdeditor) +[![ENV](https://img.shields.io/badge/中文-v0.1.17-blue.svg)](./README_CN.md) +[![ENV](https://img.shields.io/badge/Gitter-v0.1.17-blue.svg)](https://gitter.im/django-mdeditor/Lobby) [![ENV](https://img.shields.io/badge/python-2.x/3.x-green.svg)](https://github.com/pylixm/django-mdeditor) [![ENV](https://img.shields.io/badge/django-1.7+-green.svg)](https://github.com/pylixm/django-mdeditor) [![LICENSE](https://img.shields.io/badge/license-GPL3.0-green.svg)](https://github.com/pylixm/django-mdeditor/master/LICENSE.txt) diff --git a/README_CN.md b/README_CN.md index cbc52a3..013cc01 100644 --- a/README_CN.md +++ b/README_CN.md @@ -2,9 +2,9 @@ # django-mdeditor -[![ENV](https://img.shields.io/badge/release-v0.1.16-blue.svg)](https://github.com/pylixm/django-mdeditor) -[![ENV](https://img.shields.io/badge/中文文档-v0.1.16-blue.svg)](./README_CN.md) -[![ENV](https://img.shields.io/badge/gitter-v0.1.16-blue.svg)](https://gitter.im/django-mdeditor/Lobby) +[![ENV](https://img.shields.io/badge/release-v0.1.17-blue.svg)](https://github.com/pylixm/django-mdeditor) +[![ENV](https://img.shields.io/badge/中文文档-v0.1.17-blue.svg)](./README_CN.md) +[![ENV](https://img.shields.io/badge/gitter-v0.1.17-blue.svg)](https://gitter.im/django-mdeditor/Lobby) [![ENV](https://img.shields.io/badge/python-2.x/3.x-green.svg)](https://github.com/pylixm/django-mdeditor) [![ENV](https://img.shields.io/badge/django-1.7+-green.svg)](https://github.com/pylixm/django-mdeditor) [![LICENSE](https://img.shields.io/badge/license-GPL3.0-green.svg)](https://github.com/pylixm/django-mdeditor/master/LICENSE.txt) diff --git a/db.sqlite3 b/db.sqlite3 index 221cae2..268a5be 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/mdeditor/views.py b/mdeditor/views.py index e7feb9e..9612a59 100644 --- a/mdeditor/views.py +++ b/mdeditor/views.py @@ -1,11 +1,10 @@ # -*- coding:utf-8 -*- import os import datetime -import json from django.views import generic from django.conf import settings -from django.http import HttpResponse +from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator from .configs import MDConfig @@ -27,23 +26,23 @@ def post(self, request, *args, **kwargs): # image none check if not upload_image: - return HttpResponse(json.dumps({ + return JsonResponse({ 'success': 0, 'message': "未获取到要上传的图片", 'url': "" - })) + }) # image format check file_name_list = upload_image.name.split('.') file_extension = file_name_list.pop(-1) file_name = '.'.join(file_name_list) if file_extension not in MDEDITOR_CONFIGS['upload_image_formats']: - return HttpResponse(json.dumps({ + return JsonResponse({ 'success': 0, 'message': "上传图片格式错误,允许上传图片格式为:%s" % ','.join( MDEDITOR_CONFIGS['upload_image_formats']), 'url': "" - })) + }) # image floder check file_path = os.path.join(media_root, MDEDITOR_CONFIGS['image_folder']) @@ -51,11 +50,11 @@ def post(self, request, *args, **kwargs): try: os.makedirs(file_path) except Exception as err: - return HttpResponse(json.dumps({ + return JsonResponse({ 'success': 0, 'message': "上传失败:%s" % str(err), 'url': "" - })) + }) # save image file_full_name = '%s_%s.%s' % (file_name, @@ -65,8 +64,8 @@ def post(self, request, *args, **kwargs): for chunk in upload_image.chunks(): file.write(chunk) - return HttpResponse(json.dumps({'success': 1, - 'message': "上传成功!", - 'url': '{0}{1}/{2}'.format(settings.MEDIA_URL, - MDEDITOR_CONFIGS['image_folder'], - file_full_name)})) + return JsonResponse({'success': 1, + 'message': "上传成功!", + 'url': os.path.join(settings.MEDIA_URL, + MDEDITOR_CONFIGS['image_folder'], + file_full_name)}) diff --git a/mdeditor_demo_app/templates/forms.html b/mdeditor_demo_app/templates/forms.html index 2554167..3701ecd 100644 --- a/mdeditor_demo_app/templates/forms.html +++ b/mdeditor_demo_app/templates/forms.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static %} diff --git a/setup.py b/setup.py index a5a07ee..2f7ad57 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='django-mdeditor', - version='0.1.16', + version='0.1.17', packages=find_packages(exclude=['mdeditor_demo', 'mdeditor_demo_app.*', 'mdeditor_demo_app']), include_package_data=True, license='GPL-3.0 License', @@ -30,6 +30,7 @@ 'Framework :: Django :: 2.0', 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', + 'Framework :: Django :: 3.0', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'Operating System :: OS Independent', @@ -40,6 +41,7 @@ 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content' ]