标签:lse info code for port none 体验 task 网站
在settings.py中设置
EMAIL_USE_SSL = True
EMAIL_HOST = ‘smtp.qq.com‘ # 如果是 163 改成 smtp.163.com
EMAIL_PORT = 465
EMAIL_HOST_USER = ‘763005825@qq.com‘ # 帐号
EMAIL_HOST_PASSWORD = ‘jffbcdknmbzvbega‘ # 密码
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
引入包
from django.core.mail import send_mail
发送邮件
send_mail(‘主题‘,"内容",‘发送账号‘,[‘接收账号‘], fail_silently=False)
selery发送邮件
celery
名词
使用
celery==3.1.25
celery-with-redis==3.0
django-celery==3.1.17
INSTALLED_APPS = (
...
‘djcelery‘,
}
...
import djcelery
djcelery.setup_loader()
BROKER_URL = ‘redis://127.0.0.1:6379/0‘
CELERY_IMPORTS = (‘应用名称.task‘)
from celery import task
from django.core.mail import send_mail
import time
@task
def sendmail():
email=‘763005825@qq.com‘
send_mail(‘reigster‘,"欢迎登录天天生鲜",‘763005825@qq.com‘,[email],fail_silently=False)
time.sleep(10)
python manage.py migrate
sudo redis-server /etc/redis/redis.conf
python manage.py celery worker --loglevel=info
#from task import *
def index(request):
sendmail.delay()
return HttpResponse("hello world")
# 专门进行验证
def validate_sql(data):
for k,val in data:
if re.match("[‘select‘ ,‘update‘,‘delete‘]", val) != None:
return False
return True
# 注册
class Register(View):
def get(self,request):
return render(request,‘index/register.html‘)
def post(self,request):
mes = {}
data=request.POST
# flag=validate_sql(data)
# if flag==False:
# mes[‘code‘] = 10015
# mes[‘message‘] = ‘输入不合法‘
# return HttpResponse(json.dumps(mes))
username=data.get(‘user_name‘)
pwd=data.get(‘pwd‘)
cpwd=data.get(‘cpwd‘)
email=data.get(‘email‘)
allow=data.get(‘allow‘)
if not all([username,pwd,cpwd,email,allow]):
mes[‘code‘]=10010
mes[‘message‘]=‘都不能为空‘
return HttpResponse(json.dumps(mes))
else:
# 用户名必须为8-12位字母
if re.match("\w{8,12}$",username)==None:
mes[‘code‘]=10011
mes[‘message‘]=‘用户名不合法‘
# if re.match("[‘select‘ ,‘update‘,‘delete‘]",username)!=None:
# mes[‘code‘]=10012
# 验证邮箱
if re.match("\w{8,12}@(163|126|qq).com$", email) == None:
mes[‘code‘] = 10012
mes[‘message‘] = ‘用户名不合法‘
return HttpResponse(json.dumps(mes))
# 验证两次输入的密码是否一致
if pwd!=cpwd:
mes[‘code‘] = 10013
mes[‘message‘] = ‘两次输入的密码不一致‘
return HttpResponse(json.dumps(mes))
# 注册
user=User(name=username,password=make_password(pwd),
token=‘23‘)
try:
user.save()
request.session[‘indexuser‘]=username
# 发送邮件
from mypro.settings import DEFAULT_FROM_EMAIL
send_mail(‘你好,欢迎注册‘,"欢迎你注册xx网站<a href=‘/authuser?"
"token=wertfgb>",DEFAULT_FROM_EMAIL,[email],fail_silently=False)
except:
mes[‘code‘] = 10018
mes[‘message‘] = ‘添加失败‘
return HttpResponse(json.dumps(mes))
mes[‘code‘]=1200
mes[‘message‘]=‘‘
return HttpResponse(json.dumps(mes))
标签:lse info code for port none 体验 task 网站
原文地址:https://www.cnblogs.com/wyf2019/p/10972625.html