Resulta que en el blog que estoy tratando de hacer quiero que se puedan subir imagenes en el post, entonces el settings lo deje configurado de la siguiente manera:
Settings.py
Código:
los archivos JS y CSS y imagenes fijas están dentro de la carpeta 'static' y las imagenes que suben los usuarios se deberían ir a la carpeta 'media' dentro de la subcarpeta 'images'. La estructura de los directorios es la siguiente:# Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/var/www/example.com/media/" MEDIA_ROOT = 'C:/Django/proyectos/torrent/media/', # 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 = '/media/' # 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 = '/static/' # URL prefix for static files. # Example: "http://example.com/static/", "http://static.example.com/" STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = ( # 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. "C:/Django/proyectos/torrent/static", )
el modelo para los post de la aplicacion es el siguiente:
(previamente instale el pillow 2.0.0 para python 3.3.2)
models.py
Código:
y las url de la aplicacion son las siguientes:#encoding:utf-8 from django.db import models from django.contrib.auth.models import User # Create your models here. class Post(models.Model): title = models.CharField(max_length=50) gender = models.CharField(max_length=15) Date = models.DateTimeField(auto_now_add=True) lang = models.CharField(max_length=50) description = models.TextField() video = models.CharField(max_length=70) image = models.ImageField(upload_to='images') uploader = models.OneToOneField(User) def __str__(self): return self.title
urls.py
Código:
from django.conf.urls import patterns, include, url from django.conf import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('torrent.views', # Examples: # url(r'^$', 'proyectos.views.home', name='home'), # url(r'^$', include('torrent.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), url(r'^media/(?P<path>.*)$','django.views.static.serve', {'document_root':settings.MEDIA_ROOT,} ), url(r'^accounts/', include('registration.urls')), # url of the home page (r"","main"), )
En concreto la url que da problemas es la de "media" alguien me puede orientar por favor ?