Home > Net >  <span data - v - db2ca0fa> django authentication code print background is five, but the captch
<span data - v - db2ca0fa> django authentication code print background is five, but the captch

Time:09-12

the background print is 5 & # xff0c; But what is verification code page display only a reason & # xff1f;

authentication code display page & # xff1a;


urls. Py page & # xff1a;

The  from the django. Contrib import adminThe from the django. Urls import pathThe from home import viewsThe from the django. Conf import SettingsThe from the django. Conf. Urls. Static import staticUrlpatterns & # 61; [Path (& # 39; The login/& # 39; , views. Login_view, name & # 61; & # 39; The login & # 39;) .Path (& # 39; Get_valid_code_img/& # 39; , views. Get_valid_code_img_view),]If Settings. The DEBUG:Urlpatterns & # 43; The & # 61; The static (Settings. STATIC_URL,Document_root & # 61; Settings. STATIC_ROOT)Urlpatterns & # 43; The & # 61; The static (Settings. MEDIA_URL,Document_root & # 61; Settings. MEDIA_ROOT)  

the py page & # xff1a;

The  from the django. HTTP import HttpResponseimport randomThe from the django. Shortcuts import renderThe from IO import BytesIO # memory managementThe from PIL import Image, ImageDraw ImageFontDef login_view (request) :Return render (request, & # 39; The login. HTML & # 39;)Def get_valid_code_img_view (request) :Def get_random_color () :Return the random randint (0, 255), the random. Randint (0, 255), random. Randint (0, 255)Img & # 61; Image. The new (& # 34; RGB & # 34; , (250, 40), color & # 61; Get_random_color ())The draw the & # 61; ImageDraw. The Draw (img)Did_font & # 61; ImageFont. Truetype (& # 34; The static/font/did. Otf & # 34; , the size & # 61; 30)for i in range(5):Random_num & # 61; STR (random randint (0, 9))Random_low_alpha & # 61; CRH (random randint (95, 122))Random_upper_alpha & # 61; CRH (random randint (65, 90))Random_char & # 61; The random choice ([random_num, random_low_alpha random_upper_alpha])The draw. The text ((I * 20 & # 43; 20, 5), random_char get_random_color (), the font & # 61; Did_font)F the & # 61; BytesIO ()Img. Save (f, & # 34; PNG & # 34;)The data & # 61; F.g etvalue ()Return an HttpResponse (data) 
  •  Tags:  
  • Related