[PYTHON] Launch my Django app

Notes for yourself Updated from time to time

** I just need to know myself, so the terms may be wrong in some places **

Create django app-load template

--Conditions --get and post are managed by view class --URL is managed by each app

1. Click CREATE on the Environments tab on the ANACONDA top screen

スクリーンショット (11).png

2. Select virtual environment details

スクリーンショット (10).png

3. Install Django from your terminal into your virtual environment

In the terminal pip install django スクリーンショット (12).png

4. Create a project.

In the terminal move cd to the directory where you want to create the project django-admin startproject any project name

5. Add application

In the terminal python manage.py startapp any app name スクリーンショット (14).png

6. Open the application

スクリーンショット (15).png

7. Move URL processing into the app

プロジェクトのurls.py

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('sns/',include('sns.urls')),
]

アプリのurls.py

from django.urls import path
from . import views
from .views import SnsView

urlpatterns = [
    path('',SnsView.as_view(),name='index'),
]


8. Move URL processing into the app

Add app to settings.py Project folder \ project name \ settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sns_app' #Add app
]

9. Create templates folder and html

App \ templates \ App name Create a template in

10. Creating a view class

from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import TemplateView


class SnsView(TemplateView):
    def get(self,request):
        self.params={}
        return render(request,'sns/index.html',self.params)

Recommended Posts

Launch my Django app
Initialize your Django app
Launch notes for existing Django applications
Prevent double launch of django commands
Django
Implement a Django app on Hy
Django Management Command Duplicate Launch Decorator
Deploy the Django app on Heroku [Part 2]
Deploy the Django app on Heroku [Part 1]
Django: Implement reusable APP settings following Django RestFrameWork
Django Tutorial (Blog App Creation) ⑤ --Article Creation Function
Launch a Flask app in Python Anywhere
Create your first app with Django startproject
Django Tutorial (Blog App Creation) ④ --Unit Test