新手上路之django项目开发(一)-----创建项目并运行
生活随笔
收集整理的這篇文章主要介紹了
新手上路之django项目开发(一)-----创建项目并运行
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一,創建項目
1,PyCharm創建
或者
2,django-admin startproject mysite
mysite 是項目名。
二,配置settings.py文件
創建templates目錄,static目錄
settings.py文件中加入:os.path.join(BASE_DIR, ‘templates’)
TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [**os.path.join(BASE_DIR, 'templates')**],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},}, ] ALLOWED_HOSTS = ['*']三,創建首頁
在template文件夾中創建index.html文件
隨便在頁面寫上“hello word!!!!”
四,創建視圖文件
在mysite/mysite文件中創建views.py文件
from django.shortcuts import renderdef index(request):return render(request, 'index.html')五,配置路由
在mysite/mysite文件中創建urls.py文件
from django.conf.urls import url from django.urls import path from django.contrib import adminfrom admin.views import indexurlpatterns = [url(r'^admin/', admin.site.urls),path('index/', index), ]六,運行項目
瀏覽器中打開:
http://127.0.0.1:8000/index/
七,項目目錄
總結
以上是生活随笔為你收集整理的新手上路之django项目开发(一)-----创建项目并运行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网站添加页面热力图--百度统计
- 下一篇: 新手上路之django项目开发(二)--