- Notifications
You must be signed in to change notification settings - Fork121
Django 基本教學 - 從無到有 Django-Beginners-Guide 📝
License
NotificationsYou must be signed in to change notification settings
twtrubiks/django-tutorial
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
這邊紀錄如何客製化 management commands
將這個 management commands 放到 musics 資料夾底下,
資料夾結構如下
musics/__init__.pymodels.pymanagement/__init__.pycommands/__init__.pywelcome.pytests.pyviews.py
然後記得一定要將 musics 加入到INSTALLED_APPS
底下,
否則 django 不會偵測.
INSTALLED_APPS= [ ......"musics",]
welcome.py 程式碼如下,
fromdjango.core.management.baseimportBaseCommandclassCommand(BaseCommand):# python3 manage.py help welcomehelp='hello django custom management commands'defadd_arguments(self,parser):# Positional argumentsparser.add_argument("name",type=str)defhandle(self,*args,**kwargs):msg=f'handle - hello django custom management commands:{kwargs["name"]}'self.stdout.write(self.style.SUCCESS("success"))self.stdout.write(msg)
使用方法也很簡單, 先來測試一下是否有正確載入,
如果有出現 welcome 代表成功,
❯ python3 manage.py help[musics] welcome
接著來測試一下指令
❯ python3 manage.py welcome testsuccesshandle - hello django custom management commands: test
如果你想 透過 vscode debug django custom management commands,
如果想定期執行, 可以搭配Linux 指令教學-Crontab 來執行定期需要執行的內容.
- Python 3.9
文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡:laughing:
MIT license
About
Django 基本教學 - 從無到有 Django-Beginners-Guide 📝
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.