Python + Django를 Windows에 설치
6808 단어 파이썬installWindows10장고HelloWorld
Python을 Windows10에 설치해보십시오.
2017 년에는 파이썬이 인기이기 때문에 파이썬을 사용해보십시오.
1. 환경
OS:Windows10 home 64bit
1.download
다음 사이트에서 설치 프로그램을 다운로드합니다.
htps //w w. py 응. 오 rg / 드 웬아 ds / 울드 드 ws /

2.install
다운로드한 설치 프로그램을 실행하여 설치합니다.
(1) "Add Python 3.6 to PATH"를 선택하고 "Install Now"를 클릭하십시오.

(2) 설치 중

(3) 완료. Close 버튼으로 닫기

3. 가상 환경 만들기
(1) virtualenv 설치
※ virtualenv는 Python 가상 환경을 만드는 도구입니다.
명령 프롬프트를 열고 pip install virtualenv를 입력하여 Enter


(2) 가상 환경 생성
C:\Python 아래에 환경을 만듭니다.
명령 프롬프트를 열고 virtualenv env1을 입력하고 Enter

(3) 장고 설치
명령 프롬프트에서 pip install django 실행

설치가 완료되면 'pip freeze'로 버전 확인
4.Hello World 만들기
Hello World를 만들어 보겠습니다.
(1) 프로젝트 만들기
명령 프롬프트에서 가상 환경에서 django-admin startproject mysite 실행
c:\>cd C:\python
c:\python>cd env1
c:\python\env1>Scripts\activate
(env1) c:\python\env1>activate
django-admin startproject mysite
다음과 같은 파일이 있습니다.
c:\python\mysite
db.sqlite3
manage.py
\mysite
settings.py
urls.py
wsgi.py
__init__.py
(2) 프로젝트에 애플리케이션 추가
애플리케이션 'myapp1' 추가
명령 프롬프트에서 가상 환경에서 'django-admin startapp myapp1' 실행
(env1) c:\python\mysite>django-admin startapp myapp1
다음과 같은 파일을 사용할 수 있습니다.
c:\python\mysite
\myapp1
└ admin.py
apps.py
models.py
tests.py
views.py
(3) urls.py를 myapp1의 폴더에 만듭니다.
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url('', views.index, name='index'),
]
(4)views.py는 다음과 같이 다시 작성합니다.
views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('<h1>Hello, myapp1!</h1>')
(5) c :\data\python\mysite\mysite\urls.py 편집
urlpatterns에 'url('myapp1/', include('myapp1.urls')),' 추가
urls.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url('myapp1/', include('myapp1.urls')),
url(r'^admin/', admin.site.urls),
]
(6)c:\data\python\mysite\mysite\settings.py
INSTALLED_APPS에 'myapp1' 추가
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp1',
]
(7) 동작 확인
명령 프롬프트를 열고 가상 환경에서 webserver를 시작합니다.
(env1) c:\python\mysite>python manage.py runserver
URL에 액세스
http://localhost:8000/myapp1/

완료
Reference
이 문제에 관하여(Python + Django를 Windows에 설치), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/t-iguchi/items/f9052d259cec7fe54a00텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)