2013-02-05 8 views
5

可能性の重複:ランダムなパスワードを作成し、ユーザー(d.email)に電子メールを経由して、これを送信するためにどのように
Django Password Generatorランダムなパスワードを作成するには? CREATE_USER機能

d = Data.objects.get(key=key)  
User.objects.create_user(username = d.name, email= d.email, password = password) 

?ジャンゴmake_random_password

+0

ユーザーmake_random_password http://stackoverflow.com/a/9481049/188955にいくつかのメール設定を定義する必要があります – JamesO

答えて

25

は、ランダムなパスワードを生成するための方法で構築されて

my_password = User.objects.make_random_password() 

それはあなたがパスワードの長さと特殊記号を制限することができるとlengthallowd_charsなどのパラメータと数字

-1

使用これをするを受け入れますランダムパスワードを作成する:

Random string generation with upper case letters and digits in Python

メールを送信する。

from django.core.mail import send_mail 
password = rand_string 
send_mail('Subject here', 'Here is the password: .'+password, 
       '[email protected]', ['[email protected]'], 
       fail_silently=False) 

そして、あなたはあなたのsettings.py

EMAIL_HOST = 'smtp.gmail.com' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = 'mypassword' 
0
def view_name(request): 
    #make random password 
    randompass = ''.join([choice('1234567890qwertyuiopasdfghjklzxcvbnm') for i in range(7)]) 

    #sending email 
    message = "your message here" 
    subject = "your subject here" 
    send_mail(subject, message, from_email, ['to_email',]) 
関連する問題