TemplateDoesNotExist:django_markdown / editor_init.html

时间:2016-05-15 06:52:24

标签: python django

我遵循qblog教程,使用python 2.7.10和django 1.9.5。

当我进入管理员的博客界面,然后点击添加博客条目时,它显示在下面:

TemplateDoesNotExist at /admin/blog/entry/add/
django_markdown/editor_init.html

但我已经安装了django-markdown。我想展示下面的代码:

models.py:

class Entry(models.Model):
    title = models.CharField(max_length=200)
    body = MarkdownField()
    slug = models.SlugField(max_length=200, unique=True)
    publish = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    tags = models.ManyToManyField(Tag)

    objects = EntryQuerySet.as_manager()

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("entry_detail", kwargs={"slug": self.slug})

    class Meta:
        verbose_name = "Blog Entry"
        verbose_name_plural = "Blog Entries"
        ordering = ["-created"]

admin.py:

from django.contrib import admin
from . import models
from django_markdown.admin import MarkdownModelAdmin
from django_markdown.widgets import AdminMarkdownWidget
from django.db.models import TextField


class EntryAdmin(MarkdownModelAdmin):
    list_display = ("title", "created")
    prepopulated_fields = {"slug": ("title",)}
    # Next line is a workaround for Python 2.x
    formfield_overrides = {TextField: {'widget': AdminMarkdownWidget}}

admin.site.register(models.Entry, EntryAdmin)
admin.site.register(models.Tag)

qblog / urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
import settings

urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^markdown/', include("django_markdown.urls")),
    url(r'^', include('blog.urls')),
)

if settings.DEBUG:
    from django.conf.urls.static import static
    urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)

1 个答案:

答案 0 :(得分:0)

您需要在项目中添加editor_init.html文件。

如果你的项目根目录是project/,那里应该有一个名为templates的目录。如果该目录不存在,请创建它(因此路径为project/templates)。

editor_init.html文件放在此目录中,一切都应该有效。

您可以在heredjango docs中找到有关设置模板https://github.com/aws/aws-sdk-android的更多信息。