Create and deploy a Django (PTVS) app using Azure Table storage

What is a NoSQL datastore for Table storage?

NoSQL (generally interpreted as "Not only SQL") is a rough taxonomy that refers to database management systems other than relational database management systems (RDBMS). Many NoSQL database management systems are highly optimized for data storage and retrieval. Some have minimized functionality for that optimization. A key-value database that can store only a "value" and a "key" for retrieving it is a prime example. From the wiki Simply put, the NoSQL database environment is a non-relational, widely distributed database system that enables fast, dynamic, and high-speed, dynamic organization and analysis of vast amounts of data of a wide variety of types. Quote This storage service using NoSQL is called NoSQL data store and is provided on Azure.

Django application creation

This is a continuation of Last time. I will explain the Python package for using NoSQL. I will explain a part, but for details [here](https://github.com/yuesan/azure-content-jajp/blob/master/articles/storage/storage-python-how-to-use-table-storage .md)

Python Azure Storage Package

** Create table ** ** TableService **: Access NoSQL datastore on Azure ** create_table **: Create table

account_name = 'Storage account name'
account_key = 'key(Any of multiple keys is fine)'
table_service = TableService(account_name=account_name, account_key=account_key)
table_service.create_table('mytasks')

** Extract ** ** table_service.query_entities ('table name','','record specification') ** Converted to SQL: ** Select name, category From my tasks; **

tasks = table_service.query_entities('mytasks', '', 'name,category')
for task in tasks:
    print(task.name)
    print(task.category)

** Insert **

table_service.insert_entity('mytasks', {'PartitionKey':name+category, 'RowKey':name, 'name':name, 'category':category})     

replace Replace if present in entity, insert otherwise Specify ** PartitionKey ** and ** RowKey ** for the second and third arguments as well.

task = {'name':YUKI, 'category':Friends}
table_service.insert_or_replace_entity('mytasks', name+category, name, task)

update Records can be updated by specifying ** PartitionKey ** and ** RowKey **

table_service.update_entity('mytasks', partition_key, row_key, {'name': name, 'category':category})

** Delete entity ** If you want to delete an entity, you can delete it by specifying ** PartitionKey ** and ** RowKey **.

table_service.delete_entity('mytasks',name+category,name)

** Delete table **

table_service.delete_table('tasktable')

Django application creation

Last time was slightly modified to add a delete function.

views.py


from django.shortcuts import render
from django.http import HttpRequest
from django.template import RequestContext
from datetime import datetime

from django.http import HttpResponse
from django.template.loader import render_to_string
from azure.storage.table import TableService, Entity

account_name = 'Storage name'
account_key = 'Storage key'
table_service = TableService(account_name=account_name, account_key=account_key)
table_service.create_table('mytasks')

def list_tasks(request):      
    entities = table_service.query_entities('mytasks', '', 'name,category')
    html = render_to_string('app/test.html', {'entities':entities})     
    return HttpResponse(html)
 
 
def add_task(request):     
    name = request.GET['name']     
    category = request.GET['category']        
    table_service.insert_entity('mytasks', {'PartitionKey':name+category, 'RowKey':name, 'name':name, 'category':category})     
    entities = table_service.query_entities('mytasks', '', 'name,category')     
    html = render_to_string('app/test.html', {'entities':entities})     
    return HttpResponse(html)
 

def update_task(request):     
    name = request.GET['name']     
    category = request.GET['category']
    table_service.delete_entity('mytasks',name+category,name)
    entities = table_service.query_entities('mytasks', '', 'name,category')         
    html = render_to_string('app/test.html', {'entities':entities})     
    return HttpResponse(html)

test.html


<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>     
    <body>
        <h2>My Tasks</h2> <br>     
        <table border="1">
            <tr>
                <td>Name</td>
                <td>Category</td>
                <td>Check</td>
            </tr>     
            {% for entity in entities %}     
                <form action="update_task" method="GET">
                    <tr>
                        <td>{{entity.name}} <input type="hidden" name='name' value="{{entity.name}}"></td>     
                        <td>{{entity.category}} <input type="hidden" name='category' value="{{entity.category}}"></td>   
                        <td><input type="submit" value="Delete"></td> 
                    </tr>     
                </form>     
            {% endfor %}     
        </table>     
        <br>     
        <hr>    
        <table border="1">
            <form action="add_task" method="GET">
                <tr>
                    <td>Name:</td
                    ><td><input type="text" name="name"></input></td>
                </tr>     
                <tr>
                    <td>Category:</td>
                    <td><input type="text" name="category"></input></td>
                </tr>     
                <tr>
                    <td><input type="submit" value="add task"></input></td>
                </tr>     
            </form>     
        </table>     
    </body>     
</html>

urls.py


urlpatterns = [
    url(r'^$', 'app.views.list_tasks'),
    url(r'^list_tasks$', 'app.views.list_tasks'),
    url(r'^add_task$', 'app.views.add_task'),
    url(r'^update_task$', 'app.views.update_task'),
]

Run

Try only the newly implemented delete function Click the delete button to delete the record

** * As far as I actually checked, I can't delete tables and records in the storage on Azure. If you want to delete the table on Azure, you can recreate the storage. However, it is annoying and difficult, so it is recommended to remove it programmatically (using a package). ** **

1.png 2.png

Deploy a Django app with Table storage on Azure

Right-click on the project and select ** [Publish] ** 1.png

Select Microsoft Azure Web Apps ** [Publish] ** 2.png

Create a new app with [New]! 3.png

Give any name to ** Web App name ** and ** App service plan ** If there is no ** Resource group **, please create it 4.png

Basically, just check, if you want to make detailed settings, select ** [Next] ** There is no problem, so as it is ** [Issue] ** Then, it will be uploaded on Azure 5.png

Finally from the portal management screen of Azure [App Service] ➡︎ [Created APP name] ➡︎ [Overview] ➡︎ [URL] If you select, the Django application you created earlier will work! !! 6.png

Recommended Posts

Create and deploy a Django (PTVS) app using Azure Table storage
Deploy a Django app made with PTVS on Azure
Azure table storage with PTVS Flask app
Create a Mac app using py2app and Python3! !!
How to use Azure Table storage from Django (PTVS)
Create a shogi game record management app using Django 4 ~ Create View ~
[Azure] Create, deploy, and relearn a model [ML Studio classic]
Create a shogi game record management app using Django 6 ~ Template division ~
Create and deploy Flask apps in PTVS
Create a shogi game record management app using Django 3 ~ Django default management site settings ~
Create a Todo app with Django ④ Implement folder and task creation functions
Create a beauty pageant support app using PyLearn2
Create a web map using Python and GDAL
Azure External Storage MySQL Challenges with Django (PTVS)
Until you create a new app in Django
Create a web app that converts PDF to text using Flask and PyPDF2
Create a Django schedule
Create a Todo app with Django REST Framework + Angular
I tried to create a table only with Django
Create a native GUI app with Py2app and Tkinter
Create a Todo app with the Django REST framework
Create a Todo app with Django ③ Create a task list page
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
To myself as a Django beginner (1) --Create a project app--
To myself as a Django beginner (4) --Create a memo app--
Create a Todo app with Django ⑤ Create a task editing function
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
Create a dictionary by searching the table using sqlalchemy
When I deploy a Django app with Apache2 and it no longer reads static files
Create a deploy script with fabric and cuisine and reuse it
Create a Todo app with Django ① Build an environment with Docker
Create a simple CRUD app using Django's generic class view
Create a homepage with django
Create a Django login screen
Create and list Django models
Create a temporary file with django as a zip file and return it
Deploy Django + React from scratch to GKE (3) Create a GCP project
Web App Development Practice: Create a Shift Creation Page with Django! (Shift creation page)
Create a simple scheduled batch using Docker's Python Image and parse-crontab
Create a pandas Dataflame by searching the DB table using sqlalchemy
How to format a table using Pandas apply, pivot and swaplevel
Create a TalkBot easily using Discord.py and A3RT's Talk API (pya3rt).
Make a scraping app with Python + Django + AWS and change jobs
How to deploy a Django app on heroku in just 5 minutes
Creating a Shogi Game Record Management App Using Django 1-Environment Construction-
Steps to create a Django project
Deploy a Django application with Docker
Create a nested dictionary using defaultdict
Creating a simple table using prettytable
Implement a Django app on Hy
Create a CRUD API using FastAPI
Deploy Django in 3 minutes using docker-compose
Create a C wrapper using Boost.Python
Create a file uploader with Django
Create a LINE Bot in Django
Web App Development Practice: Create a Shift Creation Page with Django! (Introduction)
Build your Django app on Docker and deploy it to AWS Fargate
Deploy Django + React from scratch to GKE (4) Create cluster and container PUSH
Create a stack with a queue and a queue with a stack (from LetCode / Implement Stack using Queues, Implement Queue using Stacks)