django-admin startproject 工程名字
為思茅等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及思茅網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、思茅網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
python manage.py startapp 應(yīng)用名
#后臺(tái)認(rèn)證數(shù)據(jù)表遷移
D:\pythonspacen\djano\guest>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK
#創(chuàng)建用戶
D:\pythonspacen\djano\guest>manage.py createsuperuser
Username (leave blank to use 'admin'):
Email address: admin@admin.com
Password:
Password (again):
The password is too similar to the email address.
Password:
Password (again):
Superuser created successfully.
from django.contrib import admin
from django.urls import path
from sign import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index),
path('index/', views.index),
path('accounts/login/', views.index), # 認(rèn)證系統(tǒng)
path('Login/', views.Login),
path('logout/', views.logout), # 退出系統(tǒng)
path('event_manage/', views.event_manage),
]
from django.contrib.messages.storage import session
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import auth
from django.contrib.auth.decorators import login_required
def index(request):
return render(request, "index.html")
# 使用django登錄
def Login(request):
if request.method == 'POST':
login_username = request.POST.get('username', '')
login_password = request.POST.get('password', '')
# 使用框架系統(tǒng)的用戶系統(tǒng)
user = auth.authenticate(username=login_username, password=login_password)
if user is not None:
auth.login(request, user)
request.session['user'] = login_username
response = HttpResponseRedirect('/event_manage/')
return response
elif login_password == "" and login_username == "":
return render(request, "index.html", {'error': 'username or password null'})
else:
return render(request, "index.html", {'error': 'username or password error!'})
else:
return render(request, "index.html")
# 列表
@login_required
def event_manage(request):
# username = request.COOKIES.get("user", "")
username = request.session.get('user', '')
conten = {'infon': "login success!", 'user': username}
return render(request, "event_manage.html", conten)
# 退出
@login_required
def logout(request):
# 使用框架系統(tǒng)退出
auth.logout(request)
# 調(diào)轉(zhuǎn)到頁(yè)面
response = HttpResponseRedirect('/index/')
return response
使用剛才注冊(cè)的用戶名與密碼登錄
登錄頁(yè)面
發(fā)布會(huì)列表
退出
Welcome,{{ user }}
{{ infon }}