mercredi 20 septembre 2017

Django uploading images

I want to upload images in the django admin interface. During development everything works fine but when I put the files on my server it doesn't work. I have two different paths on my Server. One where I put all my source files and one where I put all the static files.

Path for source files:/htdocs/files/project/

Path for static files: /htdocs/html/project/

If I upload an image, then it is saved in /htdocs/files/project/media/. But I want to save it in /htdocs/html/project/. How can I change the path?

Here are my settings:

STATIC_URL = '/static/'

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    '/var/www/ssd1257/htdocs/html/'
) 

And here is my model:

class News(models.Model):
    title = models.CharField(max_length=200, null=False)
    date = models.DateField(null=False, default=datetime.now)
    text = models.TextField(null=False, blank=True)
    image = models.ImageField(upload_to="./news/")

Aucun commentaire:

Enregistrer un commentaire