pip install django-mdeditor
[
'django.contrib.admin'
,'django.contrib.auth'
,'django.contrib.contenttypes'
,'django.contrib.sessions'
,'django.contrib.messages'
,'django.contrib.staticfiles'
,# 新插入的corsheaders,之前的不
'corsheaders'
,# 註冊markdown的應用
'mdeditor'
,'report',]
media_url =
'/media/'
media_root = os.path.join(base_dir,
'media'
)# 順便配置下靜態資源的根目錄
static_root = os.path.join(base_dir,
'static'
)
from django.contrib import admin
from django.urls import path, include, re_path
from django.views.static import serve
from report.views import get_report
from restful_api.settings import static_root, media_root
urlpatterns =
[ path(
'admin/'
, admin.site.urls)
, path(
'report/'
, get_report)
,# 配置mdeditor路由
path(r'mdeditor/'
, include(
'mdeditor.urls'))
,# django關閉debug模式後,靜態檔案無法訪問,這裡要設定下靜態檔案的訪問路由
re_path(r'^static/(?p.*)$'
, serve,),
re_path(r'^media/(?p.*)'
, serve,),
]
python manage.py collectstatic
from django.db import models
from mdeditor.fields import mdtextfield
class
report
(models.model)
: title = models.charfield(max_length=
120, verbose_name=
"標題"
) content = mdtextfield(max_length=
1000
, verbose_name=
"測試報告"
)
# settings.py中配置該值
x_frame_options =
'sameorigin'
Django admin簡單操作
1.先在admin中註冊模組 from django.contrib import admin register your models here.from multiorm import models admin.site.register models.book admin.site.regis...
django admin站點管理
一 使用python manage.py createsuperuser建立乙個超級使用者 登入進入後台管理頁面 admin.site.register 類名 註冊模型類 頁屬性 list display 在admin後台頁面需要顯示模型的字段 list filter 過濾器,相當於group by...
Django admin簡單介紹
生成同步資料庫的指令碼 python manage.py makemigrations同步資料庫 python manage.py migrate建立後台使用者 python manage.py createsuperuser訪問 admin 介面 在 admin.py 上修改 from djang...