作者文章归档:daxiahy

09. xadmin 安装 使用

  1. 使用命令安装
pip install xadmin
  1. 在settings中 把xadmin以及crispy_forms添加到apps中
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'mirror',
    'xadmi

阅读全文 →

10.用户登陆

1. index页面

在url.py文件下写入以下代码设置index

代码中的'hello.html'为你的index页面

from django.views.generic import TemplateView

urlpatterns = [
    url('^$', TemplateView.as_view(template_name='hello.html'), name="index"),
    ]

静态问件配置

在settings.py文件中最后一行修改成以下代码

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join

阅读全文 →

11.form的应用

form 表单可以有效的防止无效的用户名登陆或表单提交而对服务器产生的压力

  1. 在app路径下新建forms.py
from django import forms
from captcha.fields import CaptchaField


class LoginForm(forms.Form):
    username = forms.CharField(required=True)
    password = forms.CharField(required=True, min_length=5)


# 注册form
class RegisterForm(forms.For

阅读全文 →

12. 验证码功能

4. 验证码功能

  1. 安装验django证码插件 官方文档链接
1.pip install  django-simple-captcha

2.Add captcha to the INSTALLED_APPS in your settings.py

3.Run python manage.py migrate

4.Add an entry to your urls.py:

urlpatterns += [
    url(r'^captcha/', include('captcha.urls')),
]
# 注,要导入includ包 from django.conf.urls impo

阅读全文 →

13. 用户注册及邮件发送

前端页面中的跳转链接可以写成 href="{% url 'index' %}" 格式,而不是 herf="index.html"

用户注册

  1. 注册的view
# _*_ coding: utf-8 _*_
from django.shortcuts import render
from django.views.generic.base import View
from django.contrib.auth.hashers import make_password

from users.forms import LoginForm, RegisterForm
from users.mo

阅读全文 →

14. 找回密码

找回密码

  1. view
class ForgetPwdView(View):
    def get(self, request):
        forget_form = ForgetForm()
        return render(request, "forgetpwd.html", {"forget_form":forget_form})

    def post(self, request):
        forget_form = ForgetForm(request.POST)
        if forget_form.is_valid():
        

阅读全文 →

03.表单页面数据库配置

数据库配置

找到settings.py中的DATABASES配置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "mxonline",
        'USER': "root",
        'HOST': '127.0.0.1',
        'PASSWORD': "root"
    }
}

使用python mysql时需要安装对应的mysql-python库

pip install mysql-python
# windows下安装出

阅读全文 →

01.virtualenv安装配置

virtualenv

virtualenv 优点

  1. 使不同开发环境独立
  2. 环境升级不影响其他应用 不影响全局环境
  3. 防止系统包版本管理混乱冲突
    # 安装
    pip install virtualenv
    # 新建 testvir  默认安装在cmd运行目录
    vitualenv testvir
    # 进入virtualenv 运行 activate.bat
    cd testvir/Scripts
    # 运行完 activate.bat 后查看 当前虚拟环境安装了那些库
    pip list 
    # 退出环境
    ./deactivate.bat

virtualenvwrapper

# 安装 linux下不需要-win

阅读全文 →