Create django project and virtual environment

1. Create a django project.
Enter the project storage path cd C:\pythonWeb  
to create a django project. django-admin startproject myjob
creates an application in the django project. python manage.py startapp first
starts the project and enters the project directory. python manage.py runserver
starts the project setting port. Enter the project directory python manage.py runserver 8080    
2. Use venv to create a virtual environment.
Enter the environment storage path cd C:\pythonEnv to
create the environment. python -m venv myenv
enter the environment directory C:\pythonEnv\myenv\Scripts
to activate the virtual environment. activate
to close the virtual environment. deactivate

3. Create a running project

1. First execute 1, and then create the file views.py in a directory

from django.http import HttpResponse
# Create your views here.
def hello(request):
    return HttpResponse("hello word")

2. Open the url.py file,

from django.contrib import admin
from django.urls import path
from . import views #Replace the files imported into the current folder with dots
urlpatterns = [
    path('', views.hello,name='hello'),
    path('admin/', admin.site.urls),
]

Guess you like

Origin blog.csdn.net/qq_40333984/article/details/125772003