{"title":"FAQ: Usando Django","version":"1.9","locale":"es","docname":"faq/usage","url":"/es/1.9/faq/usage/","canonical":"https://djangodocs.dev/es/1.9/faq/usage/","summary":"¿Por qué me aparece un importando un error importando DJANGO_SETTINGS_MODULE? Link to this heading # Asegúrese de que: The environment variable…","html":"<h1>FAQ: Usando Django<a class=\"heading-anchor\" href=\"#faq-using-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"why-do-i-get-an-error-about-importing-django-settings-module\">\n<h2>¿Por qué me aparece un importando un error importando DJANGO_SETTINGS_MODULE?<a class=\"heading-anchor\" href=\"#why-do-i-get-an-error-about-importing-django-settings-module\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Asegúrese de que:</p>\n<ul class=\"simple\">\n<li><p>The environment variable DJANGO_SETTINGS_MODULE is set to a\nfully-qualified Python module (i.e. «mysite.settings»).</p></li>\n<li><p>Said module is on <code class=\"docutils literal notranslate\"><span class=\"pre\">sys.path</span></code> (<code class=\"docutils literal notranslate\"><span class=\"pre\">import</span> <span class=\"pre\">mysite.settings</span></code> should work).</p></li>\n<li><p>El módulo no tiene errores de sintaxis (por supuesto).</p></li>\n</ul>\n</section>\n<section id=\"i-can-t-stand-your-template-language-do-i-have-to-use-it\">\n<h2>No puedo soportar su lenguaje de plantillas. Tengo que usarlo?<a class=\"heading-anchor\" href=\"#i-can-t-stand-your-template-language-do-i-have-to-use-it\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>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.</p>\n</section>\n<section id=\"do-i-have-to-use-your-model-database-layer\">\n<h2>¿Tengo que utilizar su modelo/capa de base de datos?<a class=\"heading-anchor\" href=\"#do-i-have-to-use-your-model-database-layer\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Nope. Just like the template system, the model/database layer is decoupled from\nthe rest of the framework.</p>\n<p>The one exception is: If you use a different database library, you won’t get to\nuse Django’s automatically-generated admin site. That app is coupled to the\nDjango database layer.</p>\n</section>\n<section id=\"how-do-i-use-image-and-file-fields\">\n<h2>¿Cómo uso los campos de imagenes y archivos?<a class=\"heading-anchor\" href=\"#how-do-i-use-image-and-file-fields\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Utilizar una:class:~django.db.models.FileField o una :class:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>~django.db.models.ImageField`en un modelo toma unos pocos pasos:</p>\n<ol class=\"arabic simple\">\n<li><p>In your settings file, you’ll need to define <a class=\"reference internal\" href=\"/es/1.9/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a> as\nthe full path to a directory where you’d like Django to store uploaded\nfiles. (For performance, these files are not stored in the database.)\nDefine <a class=\"reference internal\" href=\"/es/1.9/ref/settings/#std-setting-MEDIA_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_URL</span></code></a> as the base public URL of that directory.\nMake sure that this directory is writable by the Web server’s user\naccount.</p></li>\n<li><p>Add the <a class=\"reference internal\" href=\"/es/1.9/ref/models/fields/#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FileField</span></code></a> or\n<a class=\"reference internal\" href=\"/es/1.9/ref/models/fields/#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ImageField</span></code></a> to your model, defining the\n<a class=\"reference internal\" href=\"/es/1.9/ref/models/fields/#django.db.models.FileField.upload_to\" title=\"django.db.models.FileField.upload_to\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">upload_to</span></code></a> option to specify a\nsubdirectory of <a class=\"reference internal\" href=\"/es/1.9/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a> to use for uploaded files.</p></li>\n<li><p>All that will be stored in your database is a path to the file\n(relative to <a class=\"reference internal\" href=\"/es/1.9/ref/settings/#std-setting-MEDIA_ROOT\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MEDIA_ROOT</span></code></a>). You’ll most likely want to use the\nconvenience <a class=\"reference internal\" href=\"/es/1.9/ref/models/fields/#django.db.models.fields.files.FieldFile.url\" title=\"django.db.models.fields.files.FieldFile.url\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">url</span></code></a> attribute\nprovided by Django. For example, if your\n<a class=\"reference internal\" href=\"/es/1.9/ref/models/fields/#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ImageField</span></code></a> is called <code class=\"docutils literal notranslate\"><span class=\"pre\">mug_shot</span></code>, you can get\nthe absolute path to your image in a template with\n<code class=\"docutils literal notranslate\"><span class=\"pre\">{{</span> <span class=\"pre\">object.mug_shot.url</span> <span class=\"pre\">}}</span></code>.</p></li>\n</ol>\n</section>\n<section id=\"how-do-i-make-a-variable-available-to-all-my-templates\">\n<h2>¿Cómo hago que una variable esté disponible en todas mis plantillas?<a class=\"heading-anchor\" href=\"#how-do-i-make-a-variable-available-to-all-my-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Sometimes your templates just all need the same thing. A common example would\nbe dynamically-generated menus. At first glance, it seems logical to simply\nadd a common dictionary to the template context.</p>\n<p>La solución correcta es usar un <code class=\"docutils literal notranslate\"><span class=\"pre\">RequestContext</span></code>. Los detalles de cómo hacer esto están aquí: <a class=\"reference internal\" href=\"/es/1.9/ref/templates/api/#subclassing-context-requestcontext\"><span class=\"std std-ref\">Subclassing Context: RequestContext</span></a>.</p>\n</section>","rootId":"faq-using-django","toc":[{"title":"¿Por qué me aparece un importando un error importando DJANGO_SETTINGS_MODULE?","anchor":"why-do-i-get-an-error-about-importing-django-settings-module","children":[]},{"title":"No puedo soportar su lenguaje de plantillas. Tengo que usarlo?","anchor":"i-can-t-stand-your-template-language-do-i-have-to-use-it","children":[]},{"title":"¿Tengo que utilizar su modelo/capa de base de datos?","anchor":"do-i-have-to-use-your-model-database-layer","children":[]},{"title":"¿Cómo uso los campos de imagenes y archivos?","anchor":"how-do-i-use-image-and-file-fields","children":[]},{"title":"¿Cómo hago que una variable esté disponible en todas mis plantillas?","anchor":"how-do-i-make-a-variable-available-to-all-my-templates","children":[]}],"breadcrumbs":[{"docname":"faq/index","title":"FAQ de Django","url":"/es/1.9/faq/"}],"prev":{"docname":"faq/install","title":"FAQ: Instalación","url":"/es/1.9/faq/install/"},"next":{"docname":"faq/help","title":"FAQ: Obteniendo ayuda","url":"/es/1.9/faq/help/"},"formats":{"html":"/es/1.9/faq/usage/","markdown":"/es/1.9/faq/usage.md","json":"/es/1.9/faq/usage.json"},"source":"https://github.com/django/django/blob/stable/1.9.x/docs/faq/usage.txt","official":"https://docs.djangoproject.com/es/1.9/faq/usage/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","fr","ja","id","pt-br","es"]}