无法让django_markdown在管理网站上运行

时间:2015-04-28 15:15:37

标签: python django markdown pythonanywhere

我在Pythonanywhere上有一个Django服务器,我正在处理一个对我来说太难的问题。在我的本地机器上,我创建了一个使用django_markdown的博客应用程序。 Markdown编辑器在管理站点上正确显示。

但是,当我尝试在Pythonanywhere服务器上做同样的事情时,我无法做任何事情让管理网站上的降价编辑器显示。

以下是我的文件:

url.py

from Tkinter import *
import Image, ImageTk,tkFileDialog

class LoadImage:
    def __init__(self,root):
        frame = Frame(root)
        self.canvas = Canvas(frame,width=900,height=900)
        self.canvas.pack()
        frame.pack()
        self.zoomcycle = 0
        self.zimg_id = None
        root.bind("<MouseWheel>", self.zoomer)
        self.canvas.bind("<Motion>", self.crop)

    def abrir(self):
        File = "nlx019PQVT1sidekro1_540.jpg"
        options={}
        options['defaultextension']='.gif'
        options['filetypes']=[('GIF','.gif'),('JPEG','.jpg'),('TIFF','.tif')]
        options['title']='Select image file'
        File=tkFileDialog.askopenfilename()
        self.orig_img = Image.open(File)
        self.img = ImageTk.PhotoImage(self.orig_img)
        self.canvas.create_image(0,0,image=self.img, anchor="nw")

    def zoomer(self,event):
        if (event.delta > 0):
            if self.zoomcycle != 4: self.zoomcycle += 1
        elif (event.delta < 0):
            if self.zoomcycle != 0: self.zoomcycle -= 1
        self.crop(event)

    def crop(self, event):
        if self.zimg_id: self.canvas.delete(self.zimg_id)
        if (self.zoomcycle) != 0:
            x,y = event.x, event.y
            if self.zoomcycle == 1:
                tmp = self.orig_img.crop((x-45,y-30,x+45,y+30))
            elif self.zoomcycle == 2:
                tmp = self.orig_img.crop((x-30,y-20,x+30,y+20))
            elif self.zoomcycle == 3:
                tmp = self.orig_img.crop((x-15,y-10,x+15,y+10))
            elif self.zoomcycle == 4:
                tmp = self.orig_img.crop((x-6,y-4,x+6,y+4))
            size = 300,200
            self.zimg = ImageTk.PhotoImage(tmp.resize(size))
            self.zimg_id = self.canvas.create_image(event.x,event.y,image=self.zimg)

root = Tk()
root.title("Crop Test")
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)

li = LoadImage(root)
filemenu.add_command(label = "Abrir", command = li.abrir)
menubar.add_cascade(label = "Archivo", menu = filemenu)
root.config(menu = menubar)
root.mainloop()

settings.py

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

urlpatterns = [
    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)

models.py

...
INSTALLED_APPS = (
    ...      
    'django_markdown',
    ...
)
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static/')

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

MARKDOWN_EDITOR_SKIN = 'simple'

admin.py

from django.db import models
from django_markdown.models import MarkdownField

class Article(models.Model):
    title = models.CharField(max_length=200)
    body = MarkdownField()
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "Article"
        verbose_name_plural = "Articles"
        ordering = ["-created"]

收集静力学。

1 个答案:

答案 0 :(得分:0)

如果您使用的是Python 2.x,则需要在<schema/>类中添加以下行:

ArticleAdmin

请务必在开头添加以下导入:

# Workaround for Python 2.x
formfield_overrides = {TextField: {'widget': AdminMarkdownWidget}}