Let's create a local website quickly with Django. Article environment Window 10 Django==3.1 Python 3.7.6
It is a prerequisite that python is installed. For now, install Django with pip install.
pip install django
Execute the command in the folder where you create the project. Hello World is the project name.
django-admin startproject HelloWorld
└─HelloWorld
│ manage.py
│
└─HelloWorld
asgi.py
settings.py
urls.py
wsgi.py
__init__.py
python manage.py startapp Goodbye
│ manage.py
│
├─Goodbye
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ tests.py
│ │ views.py
│ │ __init__.py
│ │
│ └─migrations
│ __init__.py
│
└─HelloWorld
│ asgi.py
│ settings.py
│ urls.py
│ wsgi.py
│ __init__.py
│
└─__pycache__
settings.cpython-37.pyc
__init__.cpython-37.pyc
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Goodbye',
]
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('goodbye/', include('Goodbye.urls')),
]
from django.urls import path
from . import views
urlpatterns = [
path('', views.get_data, name='get_data'),
]
from django.shortcuts import render
# Create your views here.
def get_data(request):
if "data" in request.GET:
param = {'test':request.GET.get("data")}
return render(request, 'Goodbye/index.html', param)
<html>
<body>
<p>{{test}}</p>
</body>
</html>
It took me a while to write the article, but it took about 10 minutes to display it. It's easy.
Recommended Posts