Wei-Ting
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: python --- # DAY 21 Django入門 跟著這本書學了基本的python語法20天後,今天終於要來做點東西了!! XDD 選了這本書裡的第三個project-Django的使用,在這裡我們會做出一個學習日誌,再將它部署到作用中的伺服器,讓您和您的朋友能使用它 ## 設立虛擬環境 要運用Django的話要先設立一個虛擬環境,虛擬環境是我們系統中的某個位置,可讓我們在其中安裝套件,並與其它的python套件隔開 首先我們要先開啟終端機,創一個名叫learning_log的新目錄 ``` mkdir learning_log ``` 然後切換到剛剛建立的新目錄 ``` cd learning_log ``` 接下來我們要建立一個虛擬環境的資料夾名為learning_log ``` C:\Users\ASUS\learning_log> python -m venv learning_log ``` ## 切換虛擬環境 建立完虛擬環境後我們可以用**activate**這個script來啟動它 ``` C:\Users\ASUS\learning_log> learning_log\Scripts\activate ``` 輸入完上面那行指令後我們會切換到目前的虛擬環境中,如果看到前面多了(虛擬環境資料夾名稱),就代表已成功切換,下面是成功切換後的樣子 ``` (learning_log) C:\Users\ASUS\learning_log> ``` ## 安裝Django Python有pip這個強大的套件管理工具,我們將使用它來安裝Django 輸入下面這行指令後就會開始安裝Django ``` (learning_log) C:\Users\ASUS\learning_log> pip install Django ``` 按enter之後就讓它跑一下,如果安裝成功就會看到下圖 ![](https://i.imgur.com/5wQ7qoP.png) ps.Django只能在虛擬在虛擬環境啟動下使用 ## 在Django中設定專案 下面這行命令讓Django建立一個叫做learning_log的新專案,此命令尾端的句點會建立帶有目錄結構的新專案,並在開發完成 後把應用程式部署到伺服器這個目錄結構中 ``` (learning_log) C:\Users\ASUS\learning_log> django-admin.py startproject learning_log . ``` 下面這行指令可以看learning_log目錄中含有甚麼 檔案,其中setting.py是指定Django如何與您的系統互動和管理專案,urls.py是告知Django要建立那些網頁來回應瀏覽器的請求,wsgi.py是協助Django提供它建立的專案 ``` (learning_log) C:\Users\ASUS\learning_log> dir learning_log ``` 打完dir指令後會看到下圖 ![](https://i.imgur.com/LdqdRtx.png) ## 建立資料庫 因為Django把大部分的專案與相關資訊都存在資料庫內,所以我們要建立一個可供Django運用的資料庫 當我們修改資料庫時,我們稱之為遷移,首次執行migrate命令時,會讓Django確定資料庫與專案的目前狀態有配合好 ``` (learning_log) C:\Users\ASUS\learning_log> python manage.py migrate ``` 輸入完上面的指令後會出現下圖,在這裡Django指出它會建立必要的資料庫資料表用來儲存我們在這個專案使用的資訊 ![](https://i.imgur.com/PdsLGH0.png) 然後下面這張圖是我們再輸入一次dir發現目錄裡多了一個db.sqlite3就代表建立成功了 ![](https://i.imgur.com/Id8gX7O.png) ## 查看專案 全部都建立好後,我們可以輸入runserver命令來確認Django是否有成功建立專案,如下圖所示 ![](https://i.imgur.com/qpPqevg.png) 上面的圖片中system check identified no issues是Django透過檢查確認有正確的建立專案,starting development server是指出專案的URL 所以當我們輸入上圖給的URL我們會看到Django建立成功的頁面,這樣就是把環境都架設好了 ![](https://i.imgur.com/BNrTyR1.png) #### 今天結束,各位明天見 :hand: *** 資料來源:<<python程式設計的樂趣>>-Eric Matthes著/H&C譯 資料來源:https://djangogirlstaipei.gitbooks.io/django-girls-taipei-tutorial/django/installation.html

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully