Django 搭建CMDB系统完整[1](用户登录)

***使用的mysql数据库,所以系统中要先安装mysql数据库
1、安装环境:
pip install django
python -m pip install --upgrade pip setuptools
python -m pip install django
pip install --upgrade pyls https://pypi.python.org/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 %}

 


      {{ form.username }}


      


      {{ form.password }}


      
{% csrf_token %}
      
    

  

你可能感兴趣的:(Django 搭建CMDB系统完整[1](用户登录))