服务器端代码: import socket server = socket.socket # 默认是基于TCP# 基于TCP的对象serve=socket.socket(socket.AFINET,socket.SOCKSTREAM,0)# 基于UDP的对象serve=socket.socket(socket.AFINET,socket.SOCKDGRAM,0) server.bind(('',8888)) #绑定服务器IP地址和端口 server.listen #监听是否有握手请求,参数一般不写.

Pseudo-random django secret key generator.
- Does print SECRET key to terminal which can be seen as unsafe.
from __future__ importprint_function
# Get ascii Characters numbers and punctuation (minus quote characters as they could terminate string).
chars='.join([string.ascii_letters, string.digits, string.punctuation]).replace(''', ').replace('', ').replace('', ')
SECRET_KEY='.join([random.SystemRandom().choice(chars) foriinrange(50)])

commented Oct 11, 2015

You should move from __future__ import print_function to top of the import string . Current code is trowing SyntaxError: from __future__ imports must occur at the beginning of the file exception

commented Aug 9, 2016

I made pip installation to generate django secret key

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Simple Django application that adds a new command:

This will generate a new file secretkey.txt containing a random Django secretkey. In your production settings file, replace the hardcoded key by:

You can avoid hardcoding the path of the key by using:


Django Base.lib.generate_key Import Generate_ke

Django Base.lib.generate_key Import Generate_ke Date

You can install this package from PyPi:

Django base.lib.generate_key import generate_ke pdf

Django Base.lib.generate_key Import Generate_ke Pdf

Then you will need to add it to the Django's INSTALLED_APPS setting:

Django Base.lib.generate_key Import Generate_ke Video

You can now use

Django Base.lib.generate_key Import Generate_ke Album

Run this command once in your local environment, and every time you deploy your app (on the remote host), to make sure the file exists.

Coments are closed
Scroll to top