FAQ: Usando DjangoLink to this heading
¿Por qué me aparece un importando un error importando DJANGO_SETTINGS_MODULE?Link to this heading
Asegúrese de que:
The environment variable DJANGO_SETTINGS_MODULE is set to a fully-qualified Python module (i.e. «mysite.settings»).
Said module is on
sys.path(import mysite.settingsshould work).El módulo no tiene errores de sintaxis (por supuesto).
No puedo soportar su lenguaje de plantillas. Tengo que usarlo?Link to this heading
Nosotros pensamos que nuestro motor de plantillas es la mejor cosa después de la tocineta en trozos, pero reconocemos que escoger un lenguaje de plantillas es cercano a la religión. No hay nada acerca de Django que requiera usar el lenguaje de plantillas, si estás apegado a Jinja2, Mako, o lo que sea, siéntete libre de usarlos.
¿Tengo que utilizar su modelo/capa de base de datos?Link to this heading
Nope. Just like the template system, the model/database layer is decoupled from the rest of the framework.
The one exception is: If you use a different database library, you won’t get to use Django’s automatically-generated admin site. That app is coupled to the Django database layer.
¿Cómo uso los campos de imagenes y archivos?Link to this heading
Utilizar una:class:~django.db.models.FileField o una :class:`~django.db.models.ImageField`en un modelo toma unos pocos pasos:
In your settings file, you’ll need to define
MEDIA_ROOTas the full path to a directory where you’d like Django to store uploaded files. (For performance, these files are not stored in the database.) DefineMEDIA_URLas the base public URL of that directory. Make sure that this directory is writable by the Web server’s user account.Add the
FileFieldorImageFieldto your model, defining theupload_tooption to specify a subdirectory ofMEDIA_ROOTto use for uploaded files.All that will be stored in your database is a path to the file (relative to
MEDIA_ROOT). You’ll most likely want to use the convenienceurlattribute provided by Django. For example, if yourImageFieldis calledmug_shot, you can get the absolute path to your image in a template with{{ object.mug_shot.url }}.
¿Cómo hago que una variable esté disponible en todas mis plantillas?Link to this heading
Sometimes your templates just all need the same thing. A common example would be dynamically-generated menus. At first glance, it seems logical to simply add a common dictionary to the template context.
La solución correcta es usar un RequestContext. Los detalles de cómo hacer esto están aquí: Subclassing Context: RequestContext.