擅长:python、mysql、java
<p>您可以在数秒内使用<code>max_age</code>参数,而不是使用<code>expires</code>;它将为您计算<code>expires</code>。您的<code>datetime.now()</code>的问题可能是您没有使用UTC(您可以使用<code>datetime.utcnow()</code>)。</p>
<pre><code>hr.set_cookie('user_id', user_id, max_age=30)
</code></pre>
<p>故事的寓意是:<a href="http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.set_cookie" rel="noreferrer">read the documentation</a>;它解释了需要使用UTC<code>datetime</code>对象,并描述了<code>max_age</code>。</p>