snipt

Ctrl+h for KB shortcuts

Python 3

Django mod-wsgi hook file

1
2
3
4
5
6
7
8
9
import os, sys
import django.core.handlers.wsgi

path = '/var/www/sub.example.com'
if path not in sys.path: sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.settings'

application = django.core.handlers.wsgi.WSGIHandler()
https://snipt.net/embed/c452be0500558de91cd545afb3034a1a/
/raw/c452be0500558de91cd545afb3034a1a/
c452be0500558de91cd545afb3034a1a
python3
Python 3
9
2019-08-21T07:07:43
True
False
False
/api/public/snipt/5215/
django-mod-wsgi-hook-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a> <a href="#L-9">9</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">import</span> <span class="nn">django.core.handlers.wsgi</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;/var/www/sub.example.com&#39;</span> </span><span id="L-5"><a name="L-5"></a><span class="k">if</span> <span class="n">path</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="p">:</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;DJANGO_SETTINGS_MODULE&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;project_name.settings&#39;</span> </span><span id="L-8"><a name="L-8"></a> </span><span id="L-9"><a name="L-9"></a><span class="n">application</span> <span class="o">=</span> <span class="n">django</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">handlers</span><span class="o">.</span><span class="n">wsgi</span><span class="o">.</span><span class="n">WSGIHandler</span><span class="p">()</span> </span></pre></div> </td></tr></table>
apache, django, modwsgi, python