导入custun存储问题。 Django的

时间:2010-06-28 13:55:21

标签: python django system storage

您好,我正在选择我的自定义存储系统1天。现在,当我尝试导入它时,它给了我这个错误。 我把文件models.py

from FTPStorage import FTPStorage
import datetime
from django.db import models

fs=FTPStorage()

class Upload(models.Model):
    """Uploaded files."""
    file = models.FileField(upload_to='uploads', store=fs)
    timestamp = models.DateTimeField(default=datetime.datetime.now)
    notes = models.CharField(max_length=255, blank=True)

    class Meta:
        ordering = ['-timestamp',]

    def __unicode__(self):
        return u"%s" % (self.file)

    @property
    def size(self):
        return filesizeformat(self.file.size)

这是我的views.py:

from forms import UploadForm
from models import Upload
import ftplib
import os
import datetime
from django.forms import save_instance
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from FTPStorage import FTPStorage
from django.core.files.storage import Storage

def initial(request):
    data = {

        'form': UploadForm(),
    }
    return render_to_response('upload.html', data, RequestContext(request))


def upload(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            upload = Upload()
            upload.timestamp = datetime.datetime.now()
            save_instance(form, upload)
            return HttpResponseRedirect(reverse('initial'))

和文件自定义存储系统FTPStorage.py在指令app

我有这个问题:

Request Method:     GET
Request URL:    http://localhost:2121/
Exception Type:     ViewDoesNotExist
Exception Value:    

Could not import app.views. Error was: cannot import name FTPStorage

Exception Location:     C:\BitNami DjangoStack\apps\django\django\core\urlresolvers.py in _get_callback, line 134

请帮帮我。我很困惑。

1 个答案:

答案 0 :(得分:2)

在我看来,您需要为运行时更新PYTHONPATH。根据您的错误页面,我认为您正在使用mod_python,因此请在apache中尝试此设置:

PythonPath "sys.path+['/mydir']"  

其中/ mydir是FTPStorage模块所在位置的完整路径。