[Django] Django 연습

JH Park·2021년 5월 8일
0

Web

목록 보기
6/7

welcome.html에서 버튼을 클릭하면 hello.html로 넘어가기


<git bash>
python -m venv myvenv
source myvenv/Scripts/activate

pip install django
django-admin startproject firstproject
cd firstproject

python manage.py startapp firstapp


<firstproject - firstproject - settings.py>
INSTALLED_APPS에 'firstapp.apps.FirstappConfig', 추가


firstproject - firstapp - templates 폴더 생성 - welcome.html 생성
<firstapp - templates - welcome.html>
templates = 사용자에게 보여지는 부분


<firstproject - firstapp - views.py>
def welcome(request):
	return render(request, "welcome.html">
view = 데이터 처리


<firstproject - firstproject - urls.py>
from firstapp import views
urlpatterns에 path(' ',views.welcome, name="welcome"), 추가


firstproject - firstapp - templates 폴더 생성 - hello.html 생성
<firstapp - templates - hello.html>
templates = 사용자에게 보여지는 부분


<firstproject - firstapp - views.py>
def hello(request):
	userName=request.Get['name']   //welcome에서 사용자 이름입력하면 hello에서 ~~님 반갑습니다. --> 이름 받아오기
    	return render(request, "hello.html", {"userName':userName}}
view = 데이터 처리


<firstproject - firstproject - urls.py>
urlpatterns에 path('hello/',views.hello, name="hello"), 추가


<firstapp - templates - welcome.html>
form action="hello"


python manage.py runserver

profile
Computer Engineering Student

0개의 댓글