{"title":"Come distribuire con WSGI.","version":"6.1","locale":"it","docname":"howto/deployment/wsgi/index","url":"/it/6.1/howto/deployment/wsgi/","canonical":"https://djangodocs.dev/it/6.1/howto/deployment/wsgi/","summary":"La piattaforma primaria di deploy di Django è WSGI , lo standard Python per web server ed applicazioni. Il comando di gestione di Django startproject imposta una…","html":"<h1>Come distribuire con WSGI.<a class=\"heading-anchor\" href=\"#how-to-deploy-with-wsgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>La piattaforma primaria di deploy di Django è <a class=\"reference external\" href=\"https://wsgi.readthedocs.io/en/latest/\">WSGI</a>, lo standard Python per web server ed applicazioni.</p>\n<p>Il comando di gestione di Django <a class=\"reference internal\" href=\"/it/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">startproject</span></code></a> imposta una configurazione WSGI di default minima per te, che puoi mettere a punto a seconda di quel necessita il progetto e fare in modo che ogni server di applicazione WSGI compliant la usi.</p>\n<p>Django comprende la documentazione per iniziare con i seguenti server WSGI:</p>\n<div class=\"toctree-wrapper compound\">\n<ul>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/it/6.1/howto/deployment/wsgi/granian/\">How to use Django with Granian</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/it/6.1/howto/deployment/wsgi/gunicorn/\">Come installare Django con Gunicorn</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/it/6.1/howto/deployment/wsgi/uwsgi/\">Come usare Django con uWSGI</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/it/6.1/howto/deployment/wsgi/modwsgi/\">Come usare Django con Apache e <code class=\"docutils literal notranslate\"><span class=\"pre\">mod_wsgi</span></code></a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/it/6.1/howto/deployment/wsgi/apache-auth/\">Come autenticare da Apache verso il database utenti di Django</a></li>\n</ul>\n</div>\n<section id=\"the-application-object\">\n<h2>L’oggetto <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code><a class=\"heading-anchor\" href=\"#the-application-object\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Il concetto chiave del deploy con WSGI è l”<code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> richiamabile che il server dell’applicazione usa per comunicare con il tuo codice. Comunemente è fornita come un oggetto di nome <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> in un modulo Python accessibile al server.</p>\n<p>Il comando <a class=\"reference internal\" href=\"/it/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">startproject</span></code></a> crea un file <code class=\"file docutils literal notranslate\"><span class=\"pre\">&lt;project_name&gt;/wsgi.py</span></code> che contiene tale <code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> richiamabile.</p>\n<p>E” utilizzato sia da server di sviluppo Django sia da server di produzione WSGI.</p>\n<p>I server WSGI ottengono il percorso all”<code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> chiamabile dalla loro configurazione. Il server built-in di Django, cioè il comando <a class=\"reference internal\" href=\"/it/6.1/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">runserver</span></code></a>, lo legge dall’impostazione <a class=\"reference internal\" href=\"/it/6.1/ref/settings/#std-setting-WSGI_APPLICATION\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">WSGI_APPLICATION</span></code></a>. Di norma, è impostato a <code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;project_name&gt;.wsgi.application</span></code>, che punta all”<code class=\"docutils literal notranslate\"><span class=\"pre\">application</span></code> callable in <code class=\"file docutils literal notranslate\"><span class=\"pre\">&lt;project_name&gt;/wsgi.py</span></code>.</p>\n</section>\n<section id=\"configuring-the-settings-module\">\n<h2>Configura il modulo settings<a class=\"heading-anchor\" href=\"#configuring-the-settings-module\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Quando il server WSGI carica la tua applicazione, Django ha bisogno di importare il modulo settings - che è il posto dove la tua intera applicazione è definita.</p>\n<p>Django usa la variabile d’ambiente envvar:DJANGO_SETTINGS_MODULE  per trovare il modulo di impostazioni appropriato. Deve contenere il percorso puntato al modulo delle impostazioni. Puoi usare valori diversi per lo sviluppo e la produzione; dipende tutto da come organizzi le tue impostazioni.</p>\n<p>Se questa variabile non è impostata, il file predefinito <code class=\"file docutils literal notranslate\"><span class=\"pre\">wsgi.py</span></code> lo imposta a <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite.settings</span></code>, dove <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite</span></code> è il nome del tuo progetto. Ecco come di norma <a class=\"reference internal\" href=\"/it/6.1/ref/django-admin/#django-admin-runserver\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">runserver</span></code></a> scopre il file delle impostazioni predefinite.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>Dal momento che le variabili d’ambiente sono process-wide,  questo non funziona quando fai girare più siti Django nello stesso processo. Questo accade con mod_wsgi.</p>\n<p>Per evitare questo problema, usa la modalità demone di  mod_wsgi con ogni sito nel proprio processo demone o sovrascrivi il valore dall’ambiente forzando <code class=\"docutils literal notranslate\"><span class=\"pre\">os.environ[&quot;DJANGO_SETTINGS_MODULE&quot;]</span> <span class=\"pre\">=</span> <span class=\"pre\">&quot;mysite.settings&quot;</span></code> nel tuo <code class=\"file docutils literal notranslate\"><span class=\"pre\">wsgi.py</span></code>.</p>\n</aside>\n</section>\n<section id=\"applying-wsgi-middleware\">\n<h2>Applicare il middleware WSGI<a class=\"heading-anchor\" href=\"#applying-wsgi-middleware\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Per applicare <span class=\"target\" id=\"index-3\"></span><a class=\"pep reference external\" href=\"https://peps.python.org/pep-3333/#middleware-components-that-play-both-sides\"><strong>il middleware WSGI</strong></a> puoi includere l’application object. Per esempio, potresti aggiungere queste linee alla fine di <code class=\"file docutils literal notranslate\"><span class=\"pre\">wsgi.py</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">helloworld.wsgi</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">HelloWorldApplication</span>\n\n<span class=\"n\">application</span> <span class=\"o\">=</span> <span class=\"n\">HelloWorldApplication</span><span class=\"p\">(</span><span class=\"n\">application</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Puoi anche sostituire l’applicazione Django WSGI con un’applicazione WSGI personalizzata che deleghi  successivamente all’applicazione Django WSGI, se desideri combinare un’applicazione Django con un’applicazione WSGI di un altro framework.</p>\n</section>","rootId":"how-to-deploy-with-wsgi","toc":[{"title":"L’oggetto application","anchor":"the-application-object","children":[]},{"title":"Configura il modulo settings","anchor":"configuring-the-settings-module","children":[]},{"title":"Applicare il middleware WSGI","anchor":"applying-wsgi-middleware","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"How-to guides","url":"/it/6.1/howto/"},{"docname":"howto/deployment/index","title":"Come distribuire Django","url":"/it/6.1/howto/deployment/"}],"prev":{"docname":"howto/deployment/index","title":"Come distribuire Django","url":"/it/6.1/howto/deployment/"},"next":{"docname":"howto/deployment/wsgi/granian","title":"How to use Django with Granian","url":"/it/6.1/howto/deployment/wsgi/granian/"},"formats":{"html":"/it/6.1/howto/deployment/wsgi/","markdown":"/it/6.1/howto/deployment/wsgi.md","json":"/it/6.1/howto/deployment/wsgi.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/howto/deployment/wsgi/index.txt","official":"https://docs.djangoproject.com/it/6.1/howto/deployment/wsgi/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}