商業,創業,業務,職涯,美食,葡萄酒,閱讀,網路科技。
從 Larry 創業以及商業的經驗,希望以白話的口吻,介紹給大家這個商業的世界。
FB粉專會頻繁地更新 Larry 對於商業、社會、人生的觀察與心得,歡迎大家追蹤互動~
將 Django 放在 project folder 中開發時幾點要注意的地方:
1. PYTHONPATH 要指向放 Django 的 folder (PYTHONPATH 會被加到 Python 的 sys.path 裡).
2. 在該目錄下 “django-admin.py startproject mysite” 產生 project. 此時 mysite/mysite 中有 settings.py, urls.py, wsgi.py.
3. 將 Django 改放到 project folder 中 (mysite).
4. 在 project folder 下 “python manage.py runserver” 做驗證.
5. 在 project folder 下 “python manage.py syncdb” create database tables. By https://docs.djangoproject.com/en/1.6/intro/tutorial01/
“The syncdb command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your mysite/settings.py file.”
7. 在 Django-nonrel testapp 的 project folder 下 “python manage.py runserver”, “python manage.py startapp polls” ㄧ樣可以成功 (testapp 中用的 Django 版號, 內容都與原始 Django 不同, 不是理所當然可以成功).
8. 定義你的 data models (polls/models.py), and activate them.
9. “python manage.py syncdb” 產生 model tables (Django-nonrel testapp 不用)
“Here is the resulting content for the models.py file:…” 設定 models.py. 並且試用 Django API, 成功.
12. 在 polls.admin 註冊在 admin 要出現的界面. 進入 admin 編輯 polls. For native Django, it's ok. For Django-nonrel testapp, polls 中沒有 admin.py, 進入 admin 後當然也沒有顯示 polls app 中的 objects. 但用 Django API 確認上一步輸入的 data 還在, 查詢了一下, 在 djangotoolbox/admin.py 註冊是 ok 的.
13. 接著在 project_folder/urls.py 加上你的 URL map, 在 project_folder/polls/urls.py 加上你的 URL map, project_folder/polls/views.py 加上你 URL handler function. 同時也許需要在 project_folder/polls/templates/ 中加上 html files. “views.py” 雖然名稱是 views, 但是以 MVC 架構來說, 它更像是 controller 的角色.
Additional ref:
https://developers.google.com/appengine/articles/app-engine-patch?hl=zh-TW
商業,創業,業務,職涯,美食,葡萄酒,閱讀,網路科技。
從 Larry 創業以及商業的經驗,希望以白話的口吻,介紹給大家這個商業的世界。
FB粉專會頻繁地更新 Larry 對於商業、社會、人生的觀察與心得,歡迎大家追蹤互動~