Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复验证码组件问题导致启动报错 #3

Open
wants to merge 1 commit into
base: dev3.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from django.urls import reverse
from django.core.mail import send_mail, EmailMultiAlternatives
from django.contrib.sessions.models import Session
from captcha.models import CaptchaStore
from captcha.helpers import captcha_image_url

######################################
# 第三方模块
Expand Down Expand Up @@ -141,11 +143,13 @@ def get(self, request):
######################################
class LoginView(View):
def get(self, request):
hashkey = CaptchaStore.generate_key()
image_url = captcha_image_url(hashkey)
user_login_form = UerLoginForm()
context = {
'user_login_form': user_login_form,
'user_login_form': user_login_form
}
return render(request, 'users/login/login.html', context=context)
return render(request, 'users/login/login.html', locals())

def post(self, request):
user_login_form = UerLoginForm(request.POST)
Expand Down
2 changes: 2 additions & 0 deletions opms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# media 配置
url(r'^media/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT}),

#验证码
url(r'^captcha/', include('captcha.urls')),
# users
path('', include('users.urls')),

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pytz==2018.4
six==1.11.0
tornado==5.1
xlwt==1.3.0
django-simple-captcha==0.5.9
10 changes: 8 additions & 2 deletions templates/users/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@

<!-- 验证码 -->
<div class="form-group" style="line-height: 34px; height: 34px;">
{{ user_login_form.captcha }}

<div class="input-group col-xs-12">
<input id="id_captcha_1" class="form-control user_captcha" placeholder="请输入验证码"
autocomplete="off" autocapitalize="off" spellcheck="false" name="captcha_1"
type="text"
style="width: auto;" required="">
<img class="captcha" alt="captcha" src="{{ image_url }}">
<input id="id_captcha_0" name="captcha_0" value="{{ hashkey }}" type="hidden">
</div>
<!-- 刷新验证码 -->
<script>
function refresh_captcha() {
Expand Down