我在Django中建立了一个类似博客的网站,并将其部署在Linode上。
如果我不使用Django MediumEditor,而是使用此应用程序,那么一切都会很好。包括在内,尝试获取使用此类编辑器的页面时出现服务器错误500。
我盲目地遵循了有关如何在Django中使用Medium编辑器的所有说明;在此下方是所有调用编辑器的文件。
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mediumeditor',
'blog.apps.BlogConfig'
]
...
MEDIUM_EDITOR_OPTIONS = {
'toolbar': {
'buttons': [
'bold',
'italic',
'underline',
'strikethrough',
'subscript',
'superscript',
'link',
'quote'
]
},
'placeholder': {'text': 'insert text'}
}
blog / admin.py
from django.contrib import admin
from .models import Post, Comment
from mediumeditor.admin import MediumEditorAdmin
@admin.register(Post)
class PostAdmin(MediumEditorAdmin, admin.ModelAdmin):
mediumeditor_fields = ('title', 'content')
search_fields = ['title', 'content']
list_display = ['title', 'content', 'date']
list_filter = ['title']
list_editable = ['content']
@admin.register(Comment)
class CommentAdmin(MediumEditorAdmin, admin.ModelAdmin):
mediumeditor_fields = ('content')
blog / forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.utils.safestring import mark_safe
from .models import Post, Comment
from mediumeditor.widgets import MediumEditorTextarea
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=50, required=True)
last_name = forms.CharField(max_length=50, required=True)
email = forms.EmailField(max_length=100, required=False,
help_text="Optional")
class Meta:
model = User
fields = ('username', 'password1', 'password2', 'first_name',
'last_name', 'email')
def __init__(self, *args, **kwargs):
super(SignUpForm, self).__init__(*args, **kwargs)
self.fields['username'].label = "User name"
self.fields['username'].help_text = mark_safe(""
"<ul>"
"<li>At most 150 characters</li>"
"<li>Only letters, digits and the following characters: @ _ . + -</li>"
"</ul>")
# self.fields['username'].widget.attrs.update({'placeholder': 'user name'})
self.fields['password1'].help_text = mark_safe(""
"<ul>"
"<li>At least 8 characters</li>"
"<li>Cannot be a commonly-used password</li>"
"<li>Cannot be too similar to other personal information</li>"
"<li>Cannot be entirely numeric</li>"
"</ul>")
self.fields['password2'].help_text = ""
self.fields['first_name'].label = "Name"
self.fields['last_name'].label = "Surname"
self.fields['email'].label = "E-mail address"
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ('title', 'content', 'posted')
widgets = {'title': MediumEditorTextarea(),
'content': MediumEditorTextarea()}
labels = {'posted': "Post now"}
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('content',)
widgets = {'content': MediumEditorTextarea()}
labels = {'content': "Add comment"}
templates / base.html
...
<head>
<meta charset="utf-8">
<!-- Bootstrap CSS -->
<!-- Bootstrap jQuery -->
<!-- Bootstrap Popper -->
<!-- Bootstrap JavaScript -->
{{form.media}} <!-- Medium editor -->
<!-- Google Font -->
<!-- Personal style-sheet -->
<title>...</title>
</head>
...
然后我当然会在服务器上PIP安装django-mediumeditor
。
任何关于这种情况为什么发生以及如何解决的想法,或者有助于发现我犯的任何错误的想法,都将不胜感激。