-
這個(gè)%并不是運(yùn)算符,%s這是占位符,表示這個(gè)有要表示為字符串的內(nèi)容先占著位置,后面接%(變量名),運(yùn)行時(shí)占位符這里就被替換成該變量的值
如果有多個(gè)占位符就,后面的%(變量1,變量2,變量3),按順序依次替換
查看全部 -
python manage.py createsuperuser
python manage.py. runserver
#注冊(cè)到admin
from .models import ?article
admin.site.register(article)查看全部 -
python manage.py shell
查看全部 -
python manage.py makemigrations
python manage.py migrate
查看全部 -
python manage.py migrate
open in terminal
查看全部 -
django-admin?startproject
查看全部 -
1、項(xiàng)目--》應(yīng)用
2、應(yīng)用? - view.py
3、view.py
??from django.http import HttpResponse
# Create your views here. 實(shí)現(xiàn)hello word
def hello_word(request):
? ?return HttpResponse("hello, word!")4、應(yīng)用路由? 新建urls.py
from django.urls import path,include
import ?bolg.views
urlpatterns=[path('hello_word',bolg.views.hello_word)]5、項(xiàng)目路由 urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
? ?path('admin/', admin.site.urls),
? ?path('bolg/',include('bolg.urls'))
]6、修改項(xiàng)目配置文件添加應(yīng)用
INSTALLED_APPS = [
? ?'django.contrib.admin',
? ?'django.contrib.auth',
? ?'django.contrib.contenttypes',
? ?'django.contrib.sessions',
? ?'django.contrib.messages',
? ?'django.contrib.staticfiles',
? ?'first_django.apps.FirstDjangoConfig',
? ?#myapp
? ?'bolg.apps.BolgConfig' // 初始化文件7、runserver?
http://127.0.0.1:8000/bolg/hello_word查看全部 -
Django Shell?
python?manage.py?shell
Django Admin
python?manage.py?createsuperuser
model注冊(cè)到admin
from?.models?import?Article admin.site.register(Article)
查看全部 -
模型層 (介于視圖層和數(shù)據(jù)庫間)
class?Article(models.Model): ????id=?models.AutoField(?primary_key=True) ????title=?models.TextField() ????date=models.DateTimeField(auto_now=True)
遷移到數(shù)據(jù)庫 (同步)Migration
python?manage.py?makemigrations python?manage.py?migrate
查看全部 -
View.py
from?django.http?import?HttpResponse def?hello_world(request): ????return?HttpResponse("hello?world")
urls.py
from?django.urls?import?path,?include import?blog.views urlpatterns?=?[ ????path('admin',admin.site.urls), ????path('blog/',include('blogs.urls') ]
Setting.py 配置app.py的內(nèi)容
查看全部 -
#?Django?Admin模塊 #?1.創(chuàng)建python?admin模塊?在終端輸入以下命令 python?manage.py?createsuperuser #?運(yùn)行? python?manage,py?runserver #?把定義好的Artical模型注冊(cè)到admin里面 from?.models?import?Artivcle admin.site.register(Article) #?進(jìn)入models def?__str__(self): ????return?self.title
查看全部 -
#?django?shell交njiangyi互式的python編程 #?在終端Terminal輸入 pyhton?manage.py?shell? #?引進(jìn)文章模型 from?blog.models?import?* a?=?Artical() a.title?=?'test?django?test' a.brief_content?=?'test?django?shell,?by?dongdongqiang?teacher.' a.content?=?'test?djano?shell,?new?article,?main?content.' print(a) a.save()??#?保存到數(shù)據(jù)庫 #?查詢數(shù)據(jù)庫里的models里面的所有的文章 Article.objects.all() #?個(gè)人建議還是去官網(wǎng)看文檔里面內(nèi)容更豐富,這個(gè)只是簡單的帶你理解django的框架
查看全部 -
startproject????????#創(chuàng)建一個(gè)Django項(xiàng)目 startapp????????#創(chuàng)建一個(gè)Django應(yīng)用 check????????#校驗(yàn)項(xiàng)目完整性 runserver????????#本地簡易運(yùn)行Django項(xiàng)目 shell????????#進(jìn)入Django項(xiàng)目的Python?Shell環(huán)境 test????????#執(zhí)行Django用例測試 #數(shù)據(jù)庫相關(guān) makemigrations????????#創(chuàng)建模型變更的遷移文件 migrate????????#執(zhí)行上一個(gè)命令創(chuàng)建的遷移文件 dumpdata????????#把數(shù)據(jù)庫的數(shù)據(jù)導(dǎo)出到文件 loaddata????????#把文件數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫
查看全部 -
#?創(chuàng)建blog模型層模型 from?django.db?import?models class?Artical(models.Models): ????artical_id?=?models.AotuField(primary_key?=?True) ????title?=?models.TextField() ????brief_content?=?models.TextField() ????content?=?models.TextField() ????publish_date?=?models.DateTimeField(auto_now=True) ? ? #?對(duì)模型進(jìn)行遷移,保存到數(shù)據(jù)庫里面,?在終端輸入命令 python?manage.py?makemigrations python?manage.py?migrate
查看全部 -
#?views from?django.http?import?HttpResponse def?hello_world(request): ????return?HttpResponse('hello?world') ???? #?在用層次配置路由,urls.py? from?django.urls?import?path,?include urlpattern?=?[ ????path('hello_world',?blog.views.hello_world), ????] ???? #?項(xiàng)目層次的urls的配置 urlpatterns?=?[ ????path('admin/',?admin.site.urls), ????path('blog/',?include('blog.urls')), ????] ???? #?把blog應(yīng)用添加到配置settings文件里面 INSTALL_APPS?=?[ ?? ????????'blog.apps.AppConfig', ????????] ??? ??? #?在終端Terminal輸入命令運(yùn)行 python?manage.py?runserver
查看全部
舉報(bào)