Author

Siddharth Shukla

Browsing

Inserting data in Python Inserting data into a table to store it. Use INSERT INTO table_name (column_names) VALUES (data) statement to insert into the table. Inserting A Single Row you can read how to insert a single row into the table. import mysql.connector as mysql db = mysql.connect( host=”localhost”, user=”root”, passwd=”root@123″, database=”realprogrammer” ) cursor = db.cursor() query = “INSERT INTO user (name, user_name) VALUES (%s, %s)” ## storing values in a variable values = (“Real…

## Connecting to the database import mysql.connector as mysql db = mysql.connect( host=”localhost”, user=”root”, passwd=”root@123″, ) ## creating an instance of ‘cursor’ class which is used to execute the ‘SQL’ statements in ‘Python’ cursor = db.cursor() ## creating a databse called ‘realprogrammer’ cursor.execute(“CREATE DATABASE realprogrammer”)

Creating tables in the database to store data. Before creating tables, we have to select a database first. Run the following code, to select realprogrammer database which we have selected. ## Connecting to the database import mysql.connector as mysql db = mysql.connect( host=”localhost”, user=”root”, passwd=”root@123″, db=”realprogrammer” ) cursor = db.cursor() ## creating a table called ‘users’ in the ‘datacamp’ database cursor.execute( “CREATE TABLE user (name VARCHAR(255), user_name VARCHAR(255))”)

Create a folder and go inside of the folder mkdir python_database cd python_database Installation pip install mysql-connector-python Now Create file db.py ## Connecting to the database import mysql.connector as mysql db = mysql.connect( host=”localhost”, user=”root”, passwd=”root@123″ ) print(db)

In this tutorial I will cover how to create Django user sign up/registration, login, logout. Usually I have done it from scratch. You can checkoutout. For the examples I will use an empty Django project named college. Inside the college folder I created an app student core. So every time you see college and/or core, change to the suitable project name and app name. Basic Sign Up The most simple way to implement a user…

1) What is Python? What are the advantages of utilizing Python? Python is an interpreted, high-level, general-purpose programming language. Python’s design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python is often described as a “batteries…

Create a model class Contact(models.Model): name = models.CharField(max_length=100) email = models.EmailField(max_length=100) subject = models.CharField(max_length=100) message = models.TextField() mobile = models.IntegerField() created_date = models.DateField(auto_now_add=True) Load View from views.py from .models import Contact def indexPageView(request): contact = Contact.objects.all() return render(request, “index.html”,{‘contact’: contact}) Print data in a template {% for contact in contact %} <h1>{{contact.name}}</h1> {% endfor %}