創建項目,並輸出Hello,World!!
# django-admin startproject <項目名>
# django-admin startproject mysite
mysite --------------> 項目根目錄
|-mysite --------------> Python 包
|--__init__.py
|--settings.py --> 全局設置文件
|--urls.py --> 全局路由控制
|--wsgi.py --> 服務器使用wsgi部署文件
|-manage.py --> Django項目管理
# cd mysite\mysite
# vim views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world!!")
from django.contrib import admin
from django.urls import path
from . import views # 同級目錄可直接引用
urlpatterns = [
path('admin/', admin.site.urls),
path("", views.index), # url配置views
]
# python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
July 09, 2021 - 14:49:50
Django version 2.0, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
# python manage.py migrate
將在根目錄生成db.sqlite3的文件,可通過navicat直接打開
# python manage.py createsuperuser
Username (leave blank to use 'jerry'): admin
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.
使用管理登錄後台