istommao / django-simditor Goto Github PK
View Code? Open in Web Editor NEWdjango simditor
License: MIT License
django simditor
License: MIT License
How Can I change the Language for the module
markdown都包含进去了,作者前途无量,希望积极更新,给作者点个赞
类里面:
class Post(models.Model):
title = models.CharField(max_length=70,verbose_name='文章')
image = models.ImageField(upload_to='uploads', verbose_name='图片')
body = RichTextField(verbose_name='正文')
setting里面:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
SIMDITOR_UPLOAD_PATH = 'uploads/'
SIMDITOR_IMAGE_BACKEND = 'pillow'
Nginx事件里面:
location /static {
alias /home/ubuntu/sites/downdawn.com/myblog2/static;
}
location /media {
alias /home/ubuntu/sites/downdawn.com/myblog2/media;
"simditor/views.py"
def upload_handler(request):
files = request.FILES
upload_config = settings.SIMDITOR_CONFIGS.get(
'upload', {'fileKey': 'upload'})
filekey = upload_config.get('fileKey', 'upload')
uploaded_file = files.get(filekey, 'upload')
backend = image_processing.get_backend()
if not getattr(settings, 'SIMDITOR_ALLOW_NONIMAGE_FILES', True):
try:
backend.image_verify(uploaded_file)
except utils.NotAnImageException:
retdata = {'file_path': '', 'success': False,
'msg': '图片格式错误!'}
return JsonResponse(retdata)
filename = get_upload_filename(uploaded_file.name)
saved_path = default_storage.save(filename, uploaded_file)
url = utils.get_media_url(saved_path)
is_api = settings.SIMDITOR_CONFIGS.get('is_api', False)
url = request.META.get('HTTP_ORIGIN') + url if is_api else url
retdata = {'file_path': url, 'success': True, 'msg': '上传成功!'}
return JsonResponse(retdata)
从源码的第38与第50行中,即上述代码的uploaded_file = files.get(filekey, 'upload')
与filename = get_upload_filename(uploaded_file.name)
中可以看出
uploaded_file
是一个字符串,应该不具有 name
属性吧?
请问可以在不改动源码的情况下添加自定义的图片名修改和图片压缩代码吗?
TypeError at /admin/blog/post/add/
render() got an unexpected keyword argument 'renderer'
这样方便些,
`Traceback (most recent call last):
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/utils/functional.py", line 35, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/utils/functional.py", line 35, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/local/python2.7.12/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/vagrant/dev/projects/supermarket/supermarket/urls.py", line 32, in
url(r'^simditor/', include('simditor.urls')),
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/django/conf/urls/init.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/usr/local/python2.7.12/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/simditor/urls.py", line 10, in
from . import views
File "/home/vagrant/.supermarket/lib/python2.7/site-packages/simditor/views.py", line 42
SyntaxError: Non-ASCII character '\xe5' in file /home/vagrant/.supermarket/lib/python2.7/site-packages/simditor/views.py on line 42, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details`
views.py文件中用了中文,但没申明编码方式,大家的都不报错么?
settings
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
SIMDITOR_UPLOAD_PATH = 'uploads/'
SIMDITOR_IMAGE_BACKEND = 'pillow'
SIMDITOR_TOOLBAR = [
'title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale',
'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link',
'image', 'hr', '|', 'indent', 'outdent', 'alignment', 'fullscreen',
'markdown', 'emoji'
]
SIMDITOR_CONFIGS = {
'toolbar': SIMDITOR_TOOLBAR,
'upload': {
'url': '/simditor/upload/',
'fileKey': 'upload'
},
'emoji': {
'imagePath': '/static/simditor/images/emoji/'
}
}
models
from django.db import models
from simditor.fields import RichTextField
# Create your models here.
class Post(models.Model):
title = models.CharField(verbose_name='标题', max_length=50)
content = RichTextField(verbose_name='内容')
class Meta:
verbose_name = '文章'
verbose_name_plural = verbose_name
views
from django.shortcuts import render
# Create your views here.
from .models import Post
def post(request):
post = Post.objects.all()[0]
return render(request, 'index.html', {'post': post})
html 里加了 safe
过滤器
检查元素查看 html
代码为
<pre><code class="lang-c++">class Few():
a = 0;
b= 0
</code></pre>
但是没有那个灰色的代码框
Collecting django-mdeditor Using cached https://files.pythonhosted.org/packages/e2/19/7623e00aa1eafc4c68ecff13a03505cfee003b9e8bd2350e8c6f28cc52d1/django-mdeditor-0.1.4.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-qbbpxwl5/django-mdeditor/setup.py", line 5, in <module> README = readme.read() File "/root/.virtualenvs/blogWithDjango2/lib/python3.6/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3255: ordinal not in range(128)
占用数据很大,很多程序对只支持1M传输,请问怎么只显示图片路径?
怎么重新编辑清空以前所有内容?
我想在 Django的 前端使用,比如评论这些,请问咋个使用
之前的小bug还是有
我在xmaind中跑起来之后,编辑的内容全部变成[HTML_REMOVED]。。。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.