***使用的mysql数据库,所以系统中要先安装mysql数据库
1、安装环境:
pip install django
python -m pip install --upgrade pip setuptools
python -m pip install django
pip install --upgrade pyls /simple
pip install MySQL-python
pip install mysqlclient
mkdir /dj
cd /dj
django-admin startproject cmdb
cd cmdb
python manage.py migrate
cd cmdb
vi settings.py
做如下更改
ALLOWED_HOSTS = ['*']
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',
],
},
},
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cmdb',
'USER': 'root',
'PASSWORD': 'xxxxxxx',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
vi urls.py
做如下更改
from django.conf.urls import url
from django.contrib import admin
from cmdb import views
from django.contrib.auth.views import *
urlpatterns = [
url(r'^
', login),
]
vi views.py
做如下更改
from django.shortcuts import render_to_response
def main_page(request):
return render_to_response('main_page.html', {'user':request.user })
cd /dj/cmdb
mkdir -p templates/registration
cd templates
vi main_page.html
做如下更改
Django Bookmarks
Welcome to Django Bookmarks
{% if user.username %}
Welcome {{ user.username }}!
Here you can store and share bookmarks!
{% else %}
Welcome anonymous user!
You need to login
before you can store and share bookmarks.
{% endif %}
cd registration
vi login.html
做如下更改
Django Bookmarks - User Login
User Login
{% if form.has_errors %}
Your username and password didn't match.
Please try again.
{% endif %}
Username:
{{ form.username }}
Password:
{{ form.password }}
{% csrf_token %}
如果觉得《python 搭建登陆系统_Django 搭建CMDB系统完整[1](用户登录)》对你有帮助,请点赞、收藏,并留下你的观点哦!