snipt

Ctrl+h for KB shortcuts

Python

django script initialization

1
2
3
4
5
from django.core.management import setup_environ
import sys
sys.path.append('/path/to/django/project')
import settings
setup_environ(settings)
https://snipt.net/embed/e8340fc216149972e3f3f48bab3d82fa/
/raw/e8340fc216149972e3f3f48bab3d82fa/
e8340fc216149972e3f3f48bab3d82fa
python
Python
6
2019-07-21T17:18:58
True
False
False
/api/public/snipt/2/
django-script-initialization
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">django.core.management</span> <span class="kn">import</span> <span class="n">setup_environ</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">import</span> <span class="nn">sys</span> </span><span id="L-3"><a name="L-3"></a><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="s1">&#39;/path/to/django/project&#39;</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="kn">import</span> <span class="nn">settings</span> </span><span id="L-5"><a name="L-5"></a><span class="n">setup_environ</span><span class="p">(</span><span class="n">settings</span><span class="p">)</span> </span></pre></div> </td></tr></table>
django