Django'da birkaç dosya yüklemeye çalışıyorum. Ben sunucuya inşa Djangos kullanmak benim yerel talaşlı üzerinde her şey çalışıyor ama benim verimlilik sunucusunda bu hatayı alıyorum:django dosya yükleme: [Errno 13] İzin reddedildi: '/ static'
[Errno 13] Permission denied: '/static'
benim için çalıştı bulundu bu konu dışındaki hiçbir şey hakkında çok soru var. Benim durumumda dosya izinleriyle ilgisi yok. Sorunun, django'nun dosyalarımı dosya sistemimin kök klasörüne kaydetmek istediğimi ve web sitemin kök klasöründe bulunmadığını öğrendim. '/ Static' klasörünü oluşturursam dosyalar orada oluşturulacak, ancak django onları '/ var/www/web sayfası-root/static/...' şeklinde beklediğinden, örneğin web sayfasında görüntüler gösterilmiyor.
Ben dosyaları depolamak için bir model kullanın: orada anlatıldığı gibi
if form.is_valid():
data = request.FILES['document']
doc = Document(document=data)
doc.save()
:
https://docs.djangoproject.com/en/dev/topics/http/file-uploads/ Ben Apache ve mod_wsgi kullanmak
class Document(models.Model):
title = models.CharField(max_length=100, blank=True, null=False)
document = models.FileField(upload_to='static/bachelor/documents/', max_length=500, blank=True, null=True)
ve bu şekilde kaydedin. apache dosya şuna benzer:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName webpage.de
ServerAlias www.webpage.de
DocumentRoot /var/www/webpage
Alias /media /var/www/webpage/webpage/
Alias /static /var/www/webpage/static/
<Directory /var/www/webpage>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias//var/www/webpage/apache/webpage.wsgi
<Directory /var/www/webpage>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/webpage-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/webpage-access.log combined
</VirtualHost>
Web sitemin ayarları dosyası:
Zaten benim sunucuda statik dosyalarının sunulması sorunları vardı çünkü STATICFILES_DIRS iki farklı yolları atamak zorunda# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
'/var/www/website/static/',
'/home/michael/Development/website/static/',
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
. Bu iki satır ile, geliştirme makinemde ve genel sunucu runnig apache'de her iki uçta da statik dosyalar sunabilirim.
Yapılandırmamda bir şey mi özledim yoksa bir sorun mu var? Apache'nin/var/www/website/static yerine/statik dosyaları yüklemesini neden istediğini bilmiyorum ama bu benim apache yapılandırmayla ilgili bir sorun nedeniyle olabileceğini düşünüyorum ...
Herhangi bir fikriniz var veya yardımcı olabilir ben lütfen?
teşekkür ederim
Teşekkür ederim :)))) Haklısınız ve şimdi çalışıyor. – michij83
Bu cevabı doğru olarak işaretlemelisiniz;) –