Django                
            DjangoのCRUD
        
        
            
    サーチ…
**最も単純なCRUDの例**
これらの手順がわからない場合は、 代わりにこちらから開始することを検討してください 。これらの手順はスタックオーバーフローのドキュメントから来ることに注意してください。
django-admin startproject myproject
cd myproject
python manage.py startapp myapp
myproject / settings.pyアプリをインストールする
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',
]
 myappディレクトリ内にurls.pyというファイルを作成し、次のビューで更新してください。 
from django.conf.urls import url
from myapp import views
urlpatterns = [
    url(r'^$', views.index, name='index'),
    ]
他のurls.pyファイルを次の内容で更新します。 
from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include 
from myapp import views
urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^myapp/', include('myapp.urls')),
    url(r'^admin/', admin.site.urls),
]
 myappディレクトリ内にtemplatesという名前のフォルダを作成します。次に、 templatesディレクトリ内にindex.htmlという名前のファイルを作成します。次の内容で記入してください。 
<!DOCTYPE html>
<html>
<head>
    <title>myapp</title>
</head>
<body>
    <h2>Simplest Crud Example</h2>
    <p>This shows a list of names and lets you Create, Update and Delete them.</p>
    <h3>Add a Name</h3>
    <button>Create</button>
</body>
</html>
views.pyファイルを編集することで作成できるindex.htmlを表示するビューも必要です。
from django.shortcuts import render, redirect
# Create your views here.
def index(request):
    return render(request, 'index.html', {})
あなたは今、あなたが取り組むべき基盤を持っています。次のステップは、モデルを作成することです。これは可能な最も簡単な例ですので、 models.pyフォルダーに次のコードを追加してください。
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class Name(models.Model):
    name_value = models.CharField(max_length=100)
    def __str__(self): # if Python 2 use __unicode__
        return self.name_value
これにより、Nameオブジェクトのモデルが作成され、これをコマンドラインから次のコマンドでデータベースに追加します。
python manage.py createsuperuser 
python manage.py makemigrations
python manage.py migrate
Djangoが実行する操作がいくつか表示されます。これらはテーブルをセットアップし、Djangoの管理者ビューからadminデータベースにアクセスできるスーパーユーザーを作成します。それについて言えば、私たちの新しいモデルを管理者ビューで登録することができます。 admin.pyに行き、次のコードを追加してください。
from django.contrib import admin
from myapp.models import Name
# Register your models here.
admin.site.register(Name)
コマンドラインに戻ると、 python manage.py runserverコマンドでサーバをスピンアップできます。 http:// localhost:8000 /にアクセスし、あなたのアプリを見ることができるはずです。次に、 http:// localhost:8000 / adminに移動して、プロジェクトに名前を追加してください。ログインしてMYAPPテーブルの下に名前を追加すると、この例では単純になりましたので、100文字未満であることを確認してください。 
名前にアクセスするには、どこかに表示する必要があります。 views.py内のインデックス関数を編集して、すべてのNameオブジェクトをデータベースから取り出します。
from django.shortcuts import render, redirect
from myapp.models import Name
# Create your views here.
def index(request):
    names_from_db = Name.objects.all()
    context_dict = {'names_from_context': names_from_db}
    return render(request, 'index.html', context_dict)
index.htmlファイルを次のように編集します。
<!DOCTYPE html>
<html>
<head>
    <title>myapp</title>
</head>
<body>
    <h2>Simplest Crud Example</h2>
    <p>This shows a list of names and lets you Create, Update and Delete them.</p>
    {% if names_from_context %}
        <ul>
            {% for name in names_from_context %}
                <li>{{ name.name_value }}  <button>Delete</button> <button>Update</button></li>
            {% endfor %}
        </ul>
    {% else %}
        <h3>Please go to the admin and add a Name under 'MYAPP'</h3>
    {% endif %}
    <h3>Add a Name</h3>
    <button>Create</button>
</body>
</html>
これはCRUDでの読み込みを示しています。 myappディレクトリ内にforms.pyファイルを作成します。次のコードを追加します。
from django import forms
from myapp.models import Name
class NameForm(forms.ModelForm):
    name_value = forms.CharField(max_length=100, help_text = "Enter a name")
    class Meta:
        model = Name
        fields = ('name_value',)
index.htmlを次のように更新します。
<!DOCTYPE html>
<html>
<head>
    <title>myapp</title>
</head>
<body>
    <h2>Simplest Crud Example</h2>
    <p>This shows a list of names and lets you Create, Update and Delete them.</p>
    {% if names_from_context %}
        <ul>
            {% for name in names_from_context %}
                <li>{{ name.name_value }}  <button>Delete</button> <button>Update</button></li>
            {% endfor %}
        </ul>
    {% else %}
        <h3>Please go to the admin and add a Name under 'MYAPP'</h3>
    {% endif %}
    <h3>Add a Name</h3>
    <form id="name_form" method="post" action="/">
        {% csrf_token %}
        {% for field in form.visible_fields %}
            {{ field.errors }}
            {{ field.help_text }}
            {{ field }}
        {% endfor %}
        <input type="submit" name="submit" value="Create">
    </form>
</body>
</html>
次に、次のようにしてviews.pyを更新します。
from django.shortcuts import render, redirect
from myapp.models import Name
from myapp.forms import NameForm
# Create your views here.
def index(request):
    names_from_db = Name.objects.all()
    form = NameForm()
    context_dict = {'names_from_context': names_from_db, 'form': form}
    if request.method == 'POST':
        form = NameForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return render(request, 'index.html', context_dict)
        else:
            print(form.errors)    
    return render(request, 'index.html', context_dict)
サーバーを再起動すると、Cでの作成が完了したアプリケーションの作業バージョンが完成するはずです。
TODOは更新と削除を追加します