擅长:python、mysql、java
<p>这个问题的答案通常是<a href="https://stackoverflow.com/questions/2781383/where-to-put-django-startup-code">Where To Put Django Startup Code</a>。在</p>
<blockquote>
<p>Write middleware that does this in <strong>init</strong> and afterwards raise django.core.exceptions.MiddlewareNotUsed from the <strong>init</strong>, django will remove it for all requests...</p>
</blockquote>
<p>请参阅Django<a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/#writing-your-own-middleware" rel="nofollow noreferrer">documentation on writing your own middleware</a>。在</p>