1
我一直在使用this code來生成文件上傳,我只能得到模板嘗試上傳。我想知道如果我需要配置Apache,添加一些Django設置或安裝一些更多的庫可能?500錯誤Django文件上傳
我遵循了該頁面上提到的所有步驟,但請詢問您是否懷疑我可能錯誤地攜帶了其中一個或兩個。
錯誤
jssor.slider.js
Error INTERNAL SERVER ERROR
Settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_file_form',
'django_file_form.ajaxuploader',
'jfu',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
STATIC_ROOT = '/Users/Jonathan/Documents/django/bible/bible/static/jfu'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), 'static').replace('\\','/'),
)
views.py
from django.conf import settings
from django.core.urlresolvers import reverse
from django.views import generic
from django.views.decorators.http import require_POST
from jfu.http import upload_receive, UploadResponse, JFUResponse
@require_POST
def upload(request):
# The assumption here is that jQuery File Upload
# has been configured to send files one at a time.
# If multiple files can be uploaded simulatenously,
# 'file' may be a list of files.
file = upload_receive(request)
instance = YOURMODEL(file = file)
instance.save()
basename = os.path.basename(instance.file.path)
file_dict = {
'name' : basename,
'size' : file.size,
'url': settings.MEDIA_URL + basename,
'thumbnailUrl': settings.MEDIA_URL + basename,
'deleteUrl': reverse('jfu_delete', kwargs = { 'pk': instance.pk }),
'deleteType': 'POST',
}
return UploadResponse(request, file_dict)
@require_POST
def upload_delete(request, pk):
success = True
try:
instance = YOURMODEL.objects.get(pk = pk)
os.unlink(instance.file.path)
instance.delete()
except YOURMODEL.DoesNotExist:
success = False
return JFUResponse(request, success)
urls.py文件
from django.conf.urls import patterns, include, url
from bible import views
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'bible.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^verses/', views.index),
url(r'^search/', views.search),
url(r'^contact/', views.contact),
url(r'^profile/', views.profile),
url(r'^register', views.register),
url(r'upload/', views.upload, name = 'jfu_upload'),
# You may optionally define a delete url as well
url(r'^delete/(?P<pk>\d+)$', views.upload_delete, name = 'jfu_delete'),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
models.py
from django.db import models
from django.forms import ModelForm
from django.conf import settings
# Create your models here.
class Photo(models.Model):
file = models.FileField(upload_to = settings.MEDIA_ROOT)
你能從錯誤中得到堆棧跟蹤嗎? – schillingt 2014-10-20 19:30:05
我看不到頁面上的其他內容,甚至可能是JavaScript錯誤。如果這就是你的意思,屏幕底部沒有django調試部分? – Jon 2014-10-20 19:42:48
爲什麼mediaroot沒有設置? – 2014-10-20 19:49:51