Tutorial 2: get ready the pages for sql command

create the database
==================

model.py
=======

from django.db import models


class employee(models.Model):
    user = models.CharField(max_length=100)





terminal Help(according to the status of your project database
=======

if the database and tables are not created

$python manage.py syncdb

if the database and tables are created

$python manage.py migrate

if the new tables is created in the database

python manage.py makemigrations




my status in terminal
========


erp@erp-Inspiron-N5110:~/dml$ python manage.py makemigrations

Migrations for 'dmlapp':
  0001_initial.py:
    - Create model employee
erp@erp-Inspiron-N5110:~/dml$







create or update the pages(index,insert,delete,update)
===================================



templates/delete.html
---------------


<html>
<body>
sql command

<br>
<a href="/insert/">insert</a>
<br>
<a href="/delete/">delete</a>
<br>
<a href="/update/">update</a>
 delete page


</body></html>


index.html
---------

<html>
<body>


index page
sql command

<br>
<a href="/insert/">insert</a>
<br>
<a href="/delete/">delete</a>
<br>
<a href="/update/">update</a>



</body></html>



insert.html
----------

<html>
<body>
index page
sql command

<br>
<a href="/insert/">insert</a>
<br>
<a href="/delete/">delete</a>
<br>
<a href="/update/">update</a>



</body></html>

update.html
--------

<html>
<body>
sql command

<br>
<a href="/insert/">insert</a>
<br>
<a href="/delete/">delete</a>
<br>
<a href="/update/">update</a>

update page

</body></html>




Update views.py and url.py
===================



views.py
-----


from django.shortcuts import render

# Create your views here.

def index(request):
    return render(request,'index.html')


def insert(request):
    return render(request,'insert.html')

def delete(request):
    return render(request,'delete.html')

def update(request):
    return render(request,'update.html')




url.py
-----

from django.conf.urls import include, url
from django.contrib import admin
from dmlapp.views import *
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$','dmlapp.views.index', name='index'),
    url(r'^insert/$','dmlapp.views.insert', name='insert'),
    url(r'^delete/$','dmlapp.views.delete', name='delete'),
    url(r'^update/$','dmlapp.views.update', name='update'),


]



 o/p

===





No comments:

Post a Comment