TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Django Secret Key Generator

5 pointsby ariestiyansyahalmost 9 years ago

6 comments

franciscopalmost 9 years ago
I am getting the feeling this is not a real project but a joke/critique
bwackwatalmost 9 years ago
&gt;import os<p>&gt;os.urandom(24)<p>&#x27;\x17\x96e\x94]\xa0\xb8\x1e\x8b\xee\xdd\xe9\x91^\x9c\xda\x94\t\xe8S\xa1Oe_&#x27;<p>&gt;os.urandom(24).encode(&#x27;hex&#x27;)<p>&#x27;cd48e1c22de0961d5d1bfb14f8a66e006cfb1cfbf3f0c0f3&#x27;
评论 #12256208 未加载
afshinmehalmost 9 years ago
and there is a thing in Python called __future__ so you don&#x27;t need to do this:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ariestiyansyah&#x2F;django-secret-key&#x2F;blob&#x2F;master&#x2F;django-secret-key#L10" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ariestiyansyah&#x2F;django-secret-key&#x2F;blob&#x2F;mas...</a><p>Read more: <a href="https:&#x2F;&#x2F;docs.python.org&#x2F;2&#x2F;library&#x2F;__future__.html" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;2&#x2F;library&#x2F;__future__.html</a>
评论 #12256400 未加载
soldalmost 9 years ago
Since Django 1.10 you can simply use get_random_secret_key in django.core.management.utils.<p>This will not work:<p>if python3: print (SECRET_KEY) else: print SECRET_KEY<p>because it&#x27;s a syntax error in Python 3. Instead, you can just write &quot;print (SECRET_KEY)&quot;, this works in both versions and has the same effect.
SEJeffalmost 9 years ago
Also, why not import string and use string.printable instead of hardcoding the characters? Or even:<p><pre><code> chars = string.ascii_lowercase + string.punctuation + string.digits</code></pre>
hatsunearualmost 9 years ago
Care to explain what this is?