最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

使用pycharm創(chuàng)建django項(xiàng)目(2)

2023-04-08 22:07 作者:丘奇小怪  | 我要投稿

1、創(chuàng)建一個(gè)app,終端跳轉(zhuǎn)至新建django項(xiàng)目文件夾(帶有manage.py那個(gè)文件夾)

輸入:

  • python manage.py startapp app名稱? ?或??py?manage.py startapp app名稱

這會創(chuàng)建一個(gè)文件夾,目錄如下:

  • app名稱/
    ????__init__.py
    ????admin.py? ? ? ? ? ? ? ? 【django默認(rèn)提供admin后臺管理,可以用它管理model和數(shù)據(jù)庫】
    ????apps.py? ? ? ? ? ? ? ? ? 【app啟動類,django生成你所創(chuàng)建app名稱的文件】
    ????migrations/? ? ? ? ?【數(shù)據(jù)庫變更記錄,數(shù)據(jù)遷移包,負(fù)責(zé)遷移文件 , 生成數(shù)據(jù)庫表數(shù)據(jù)

    ? ? ?__init__.py ? ? ? ? ? python?manage.py?makemigrations:生成遷移文件
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? python?manage.py?migrate:執(zhí)行遷移文件】
    ????models.py? ? ? ? ? 【對數(shù)據(jù)庫操作,數(shù)據(jù)庫表的映射】
    ????tests.py??????????????【測試文件,單元測試】
    ????views.py? ? ? ? ? ? ?【視圖函數(shù)文件】

2、注冊創(chuàng)建的app,打開settings.py文件,在 INSTALLED_APPS 里按格式添加你創(chuàng)建的app,可在app.py查看名稱

3、編寫url和視圖函數(shù)(urls.py、views.py)

  • 在views.py中輸入以下代碼:

    from django.shortcuts import render,HttpResponse

    # Create your views here.

    def index(request):
    ? ?return HttpResponse("歡迎使用小區(qū)出入門禁管理系統(tǒng)")


  • 在urls.py中輸入以下代碼:

    """mysite URL Configuration

    The `urlpatterns` list routes URLs to views. For more information please see:
    ? ?https://docs.djangoproject.com/en/3.0/topics/http/urls/
    Examples:
    Function views
    ? ?1. Add an import: ?from my_app import views
    ? ?2. Add a URL to urlpatterns: ?path('', views.home, name='home')
    Class-based views
    ? ?1. Add an import: ?from other_app.views import Home
    ? ?2. Add a URL to urlpatterns: ?path('', Home.as_view(), name='home')
    Including another URLconf
    ? ?1. Import the include() function: from django.urls import include, path
    ? ?2. Add a URL to urlpatterns: ?path('blog/', include('blog.urls'))
    """
    from django.contrib import admin
    from django.urls import path

    # 導(dǎo)入app視圖函數(shù)文件
    from app01 import views

    urlpatterns = [
    ? ?path('admin/', admin.site.urls),

    # ? ? www.xxx.com/index/ ?->函數(shù)
    ? ?path('index/',views.index),
    ]

4、啟動項(xiàng)目,終端跳轉(zhuǎn)至新建django項(xiàng)目文件夾(帶有manage.py那個(gè)文件夾),并啟動項(xiàng)目?

  • 輸入:py manage.py runserver

打開后會出現(xiàn)以下頁面:

在8080后加入/index即可訪問:


使用pycharm創(chuàng)建django項(xiàng)目(2)的評論 (共 條)

分享到微博請遵守國家法律
辽宁省| 遂平县| 兴化市| 新宾| 祥云县| 延吉市| 介休市| 镇雄县| 嘉义市| 郧西县| 贵港市| 铜陵市| 五台县| 上高县| 佛山市| 扬中市| 白山市| 安乡县| 陵水| 五莲县| 右玉县| 澄迈县| 盖州市| 阿瓦提县| 盐池县| 鄂伦春自治旗| 阿拉善左旗| 乌海市| 乌恰县| 当雄县| 疏勒县| 固镇县| 壶关县| 安庆市| 石泉县| 会东县| 德令哈市| 嘉义市| 东方市| 肇州县| 垦利县|