Kak*_*kar 5 django django-templates django-admin
我正在使用编辑器wysiwyg编辑器来编写我的内容.该页面只有wysiwyg编辑器和一个保存按钮.
HTML:
<div id="editor-wrapper">
<input type="text" id="editor-title" {%if blog %} value="{{blog.title}}" {% else %} placeholder="Your title" {% endif %}>
<textarea id="editor-redactor" name="content">
{% if blog %}
{{ blog.body }}
{% else %}
<p>Enter you body in here...</p>
{% endif %}
</textarea>
<button id="save-btn"><a href="/save-blog/">Save</a> </button>
</div>
Run Code Online (Sandbox Code Playgroud)
在urls.py中,我添加了要转到该页面的URL.
url(r'^add-update-blog/$', views.add_update_blog),
url(r'^add-update-blog/save/(?P<blog_id>\d+)$', views.add_update_blog),
Run Code Online (Sandbox Code Playgroud)
views.py:
def add_update_blog(request):
return render(request, 'editor.html')
def add_update_blog_save(request, blog_id):
blog = Blog.objects.get(id=blog_id)
return render(request, 'editor.html', {
blog: blog
})
Run Code Online (Sandbox Code Playgroud)
现在,在django-admin面板中可能有已写入内容的列表:
现在它显示列表,当我单击添加或内容时,它仅显示在管理面板内.我如何实现我想要的目标?你的帮助和指导非常非常重要.谢谢.
One way is to hijack the admin urls, and use your own views for those urls, i.e., the admin url won't change, but your editor page views will be called instead of the default admin views. (Documentation, Source)
from .views import add_update_blog, add_update_blog_save
class BlogAdmin(admin.ModelAdmin):
def get_urls(self):
urls = super(BlogAdmin, self).get_urls()
new_urls = [
url(r'^add/$', add_update_blog),
url(r'^(?P<blog_id>\d+)/change/$', add_update_blog_save),
]
return new_urls + urls # new_urls have to be first
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
370 次 |
| 最近记录: |