欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Django掃碼抽獎平臺的配置過程詳解

 更新時間:2021年01月14日 10:43:39   作者:zz891422822  
這篇文章主要介紹了Django掃碼抽獎平臺,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

安裝源
pip install django2.2
pip install mysqlclient1.4.6
使用pyharm 創(chuàng)建django 項(xiàng)目

django基本配置

在這里插入圖片描述

在settings.py中設(shè)置數(shù)據(jù)庫鏈接

在這里插入圖片描述

DATABASES = {
 'default': {
 'ENGINE': 'django.db.backends.mysql',
 'NAME': 'km',
 'USER': 'root',
 'PASSWORD': 'n4',
 'HOST': 'na.cc',
 'PORT': '3306'
 }
}

在settings.py里面配置好端口:ALLOWED_HOSTS = ['*']
配置語言 LANGUAGE_CODE = ‘zh-hans'
配置時區(qū)TIME_ZONE = ‘Asia/Shanghai'
設(shè)置時間 USE_TZ = False

創(chuàng)建APP
startapp wuzhengteng
在apps中添加 ‘wuzhengteng',

在這里插入圖片描述

在models.py中配置數(shù)據(jù)庫

from django.db import models
# Create your models here.
class User(models.Model):
 id = models.AutoField(primary_key=True)
 name = models.CharField(max_length=10)
 tel = models.CharField(max_length=11)

 def __str__(self):
 return self.name

在manage.py中執(zhí)行

# 收集數(shù)據(jù)不同
makemigrations
# 寫入數(shù)據(jù)庫
migrate
# 創(chuàng)建超級管理員
createsuperuser

將查詢寫入admin

from django.contrib import admin
from wuzhengteng.models import User
# Register your models here.

class UserAdmin(admin.ModelAdmin):
 list_display = ['id', 'name', 'tel']

admin.site.register(User, UserAdmin)

檢查數(shù)據(jù)庫是否創(chuàng)建成功
http://127.0.0.1:8000/admin
登入后

在這里插入圖片描述

配置前臺的用戶查看界面

url路徑

from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
from wuzhengteng import views #打開views

urlpatterns = [
 path('admin/', admin.site.urls),
 path('', views.user, name='home') # 添加指向到views
]

配置views

from django.shortcuts import render
from .models import User # 連接數(shù)據(jù)庫
# Create your views here.
def user(request):
 all_user = User.objects.all() # 查詢?nèi)?

 return render(request, 'index.html', {
 'all_user': all_user, # 將來結(jié)果返回html頁面
 })

前端頁面

<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="UTF-8">
 <title>test</title>
 </head>
<body>
 <table border="1">
 <tr>
 <td>用戶</td>
 <td>手機(jī)</td>
 </tr>

 {% for post in all_user %}
 <tr>
 <td>{{post.name}}</td>
 <td>{{post.tel}}</td>
 </tr>
 {% endfor %}
 </table>
</body>
</html>

測試訪問127.0.0.1:8000

在這里插入圖片描述

添加用戶界面

配置路由 path(‘scan', views.scan, name=“scan”)

views中插入

web頁面scan.htm

def scan(request):
 result = ''
 if request.method == 'POST':
 name = request.POST.get('name')
 tel = request.POST.get('tel')
 print(tel)
 db = User()
 db.name = name
 db.tel = tel
 db.save()
 result = 'success'
 return render(request, 'scan.html', {'result': result})
 else:
 return render(request, 'scan.html')

web頁面scan.html

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
 <meta charset="UTF-8">
 <title>掃碼登入</title>
</head>
<body>
<div style="width: 210px;margin:0 auto">
 <form method="post">
 {% csrf_token %}
 <label for="name">姓名:</label>
 <input type="text" name="name" style="width: 150px"><br><br>
 <label for="tel">電話:</label>
 <input type="text" name="tel" style="width: 150px"><br><br>
 <input type="reset">&nbsp;&nbsp;<input type="submit">
 </form>
 {% if result %}
 <p style="text-align: center">添加成功</p>
 {% endif %}
</div>
</body>

在這里插入圖片描述
在這里插入圖片描述

前端抽獎界面

url中添加
path(‘luck', views.luck, name=“l(fā)uck”)

views中添加

def luck(request):
 all_user = User.objects.all()

 return render(request, 'luck.html', {
 'all_user': all_user,
 })

setting里面設(shè)置靜態(tài)路徑

STATIC_URL = '/static/'
STATICFILES_DIRS=(
 os.path.join(BASE_DIR,"static"),
)

前端頁面

<!DOCTYPE html>
<html>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>jquery隨機(jī)抽獎 - 站長素材</title>
	<head>
	<script id="jquery_172" type="text/javascript" class="library" src="static/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript">
		
	$(function(){
		var alldata = new Array({% for post in all_user %}"{{post.name}}",{% endfor %});
		var num = alldata.length - 1;
		var show = $("#show");
		var btn = $("#btn");
		var open = false;
	
		function change(){
			var randomVal = Math.round(Math.random() * num);
			var prizeName = alldata[randomVal];
			show.text(prizeName);
		}
		
		function run(){
			if(!open){
				timer=setInterval(change,5);
				btn.removeClass('start').addClass('stop').text('停止');
				open = true;
			}else{
				clearInterval(timer);
				btn.removeClass('stop').addClass('start').text('開始抽獎');
				open = false;
			}
		}
		
		btn.click(function(){run();})
		
	})
		
	</script>
	<style>
	body{ background:#fff;}
	.wrap{ width:300px; margin:100px auto; font-family:"微軟雅黑";}
	.show{ width:300px; height:300px; background-color:#ff3300; line-height:300px; text-align:center; color:#fff; font-size:28px; -moz-border-radius:150px; -webkit-border-radius:150px; border-radius:150px; background-image: -webkit-gradient(linear,0% 0%, 0% 100%, from(#FF9600), to(#F84000), color-stop(0.5,#fb6c00)); -moz-box-shadow:2px 2px 10px #BBBBBB; -webkit-box-shadow:2px 2px 10px #BBBBBB; box-shadow:2px 2px 10px #BBBBBB;}
	.btn a{ display:block; width:120px; height:50px; margin:30px auto; text-align:center; line-height:50px; text-decoration:none; color:#fff; -moz-border-radius:25px; -webkit-border-radius:25px; border-radius:25px;}
	.btn a.start{ background:#80b600;}
	.btn a.start:hover{ background:#75a700;}
	.btn a.stop{ background:#00a2ff;}
	.btn a.stop:hover{ background:#008bdb;}
	</style>
	
	</head>

	<body>
	<div class="wrap">
		<div class="show" id="show">點(diǎn)擊按鈕開始抽獎</div>
		<div class="btn">
			<a href="javascript:void(0)" rel="external nofollow" class="start" id="btn">開始抽獎</a>
		</div>
	</div>
	</body>
</html>

jq文件jquery-1.7.2.min.js
放在static 文件夾下

在這里插入圖片描述

測試

在這里插入圖片描述

到此這篇關(guān)于Django掃碼抽獎平臺的文章就介紹到這了,更多相關(guān)Django掃碼抽獎內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于python歷史天氣采集的分析

    基于python歷史天氣采集的分析

    今天小編就為大家分享一篇基于python歷史天氣采集的分析,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-02-02
  • Python sklearn KFold 生成交叉驗(yàn)證數(shù)據(jù)集的方法

    Python sklearn KFold 生成交叉驗(yàn)證數(shù)據(jù)集的方法

    今天小編就為大家分享一篇Python sklearn KFold 生成交叉驗(yàn)證數(shù)據(jù)集的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python接口自動化淺析yaml配置文件原理及用法

    Python接口自動化淺析yaml配置文件原理及用法

    本文主要給大家介紹了yaml語法、yaml儲存數(shù)據(jù),封裝類讀取yaml配置文件,以及yaml的用法和其原理,有需要的朋友可以參考下,希望可以有所幫助
    2021-08-08
  • python開發(fā)中range()函數(shù)用法實(shí)例分析

    python開發(fā)中range()函數(shù)用法實(shí)例分析

    這篇文章主要介紹了python開發(fā)中range()函數(shù)用法,以實(shí)例形式較為詳細(xì)的分析了Python中range()函數(shù)遍歷列表的相關(guān)技巧,需要的朋友可以參考下
    2015-11-11
  • Python黑帽編程 3.4 跨越VLAN詳解

    Python黑帽編程 3.4 跨越VLAN詳解

    VLAN(Virtual Local Area Network),是基于以太網(wǎng)交互技術(shù)構(gòu)建的虛擬網(wǎng)絡(luò),既可以將同一物理網(wǎng)絡(luò)劃分成多個VALN,也可以跨越物理網(wǎng)絡(luò)障礙,將不同子網(wǎng)中的用戶劃到同一個VLAN中。這篇文章主要介紹了Python黑帽編程 3.4 跨越VLAN 的相關(guān)資料,需要的朋友參考下
    2016-09-09
  • 在Python中實(shí)現(xiàn)字典反轉(zhuǎn)案例

    在Python中實(shí)現(xiàn)字典反轉(zhuǎn)案例

    這篇文章主要介紹了在Python中實(shí)現(xiàn)字典反轉(zhuǎn)案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • python實(shí)現(xiàn)圖書館研習(xí)室自動預(yù)約功能

    python實(shí)現(xiàn)圖書館研習(xí)室自動預(yù)約功能

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)圖書館研習(xí)室自動預(yù)約功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • Python中random模塊常用方法的使用教程

    Python中random模塊常用方法的使用教程

    這篇文章主要給大家介紹了關(guān)于Python中random模塊常用方法的使用教程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Keras之fit_generator與train_on_batch用法

    Keras之fit_generator與train_on_batch用法

    這篇文章主要介紹了Keras之fit_generator與train_on_batch用法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • python實(shí)現(xiàn)企業(yè)微信定時發(fā)送文本消息的示例代碼

    python實(shí)現(xiàn)企業(yè)微信定時發(fā)送文本消息的示例代碼

    這篇文章主要介紹了python實(shí)現(xiàn)企業(yè)微信定時發(fā)送文本消息的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評論