在我们开始项目之前,始终建议在虚拟环境中运行您的项目,以便项目所需的所有必要依赖项都是项目环境本身,而不是整个系统。
sudo apt install python3-virtualenv
#virtualenv -p python3 <environment-name> virtualenv -p python3 ecom
#source <environment-name>/bin/activate source ecom/bin/activate
deactivate
python -m pip install django #Tip: Type `django-admin` on terminal you will see all the django commands. django-admin
在 Django 中,我们首先创建一个 Project,在其中我们创建 App。
#django-admin startproject <project-name> django-admin startproject core .
#python manage.py startapp <app-name> python manage.py startapp store
#Go to <project-name>/settings.py inside check for Installed_Apps in which write your app name. INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', #custom-app 'Store' ]
from django.contrib import admin from django.urls import path,include urlpatterns = [ path('admin/', admin.site.urls), path(' ', include('store.urls')), ]
from django.shortcuts import render def home(request): return render(request, 'home.html', {})
from django.urls import path from . import views urlpatterns = [ path(' ',views.home, name='home') ]
python manage.py runserver
以上是Django 入门:基本设置和概述的详细内容。更多信息请关注PHP中文网其他相关文章!