Pages

Subscribe:

Ads 468x60px

Featured Posts

  • ASP.NET Programming Help

    We together can help and learn from each other in a professional way, web-healer.blogspot.com is the place where we can learn.

  • Web Programming for IPHONE

    web-healer.blogspot.com and pakistanpassion.com are the really helpful plate forms to learn build professional websites for iphone using asp.net using asp.net C#, jquery, json in a professional way.

  • PDA web Applications in asp.net using C#

    A really great healping tutorial blog web-healer.blogspot.com to develop creative and attractive web applications in asp.net using c# in a convenient and easy way.

Saturday, December 24, 2022

how to save image in database using python

You are working with python and writing code for web programs, here is a solution how to upload image using python,

how to save image in database using python

 import mysql.connector

def convertToBinaryData(filename): # Convert digital data to binary format with open(filename, 'rb') as file: binaryData = file.read() return binaryData def insertBLOB(emp_id, name, photo, biodataFile): print("Inserting BLOB into python_employee table") try: connection = mysql.connector.connect(host='localhost', database='python_db', user='pynative', password='pynative@#29') cursor = connection.cursor() sql_insert_blob_query = """ INSERT INTO python_employee (id, name, photo, biodata) VALUES (%s,%s,%s,%s)""" empPicture = convertToBinaryData(photo) file = convertToBinaryData(biodataFile) # Convert data into tuple format insert_blob_tuple = (emp_id, name, empPicture, file) result = cursor.execute(sql_insert_blob_query, insert_blob_tuple) connection.commit() print("Image and file inserted successfully as a BLOB into python_employee table", result) except mysql.connector.Error as error: print("Failed inserting BLOB data into MySQL table {}".format(error)) finally: if connection.is_connected(): cursor.close() connection.close() print("MySQL connection is closed") insertBLOB(1, "Eric", "D:\Python\Articles\my_SQL\images\eric_photo.png", "D:\Python\Articles\my_SQL\images\eric_bioData.txt") insertBLOB(2, "Scott", "D:\Python\Articles\my_SQL\images\scott_photo.png", "D:\Python\Articles\my_SQL\images\scott_bioData.txt")

Friday, December 23, 2022

form validation using python

 web form validation is quit easy in python

create an html file.

  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>Index page</title>  
  6. </head>  
  7. <body>  
  8. <form method="POST" class="post-form" enctype="multipart/form-data">  
  9.         {% csrf_token %}  
  10.         {{ form.as_p }}  
  11.         <button type="submit" class="save btn btn-default">Submit</button>  
  12. </form>  
  13. </body>  
  14. </html>  

create a page modules.py
  1. from django.db import models  
  2. class Employee(models.Model):  
  3.     eid = models.CharField(max_length=20)  
  4.     ename = models.CharField(max_length=100)  
  5.     econtact = models.CharField(max_length=15)  
  6.     class Meta:  
  7.         db_table = "employee" 

now create a file forms.py

  1. from django import forms  
  2. from myapp.models import Employee  
  3.   
  4. class EmployeeForm(forms.ModelForm):  
  5.     class Meta:  
  6.         model = Employee  
  7.         fields = "__all__"  

create another file named views.py and paste the below code

  1. def emp(request):  
  2.     if request.method == "POST":  
  3.         form = EmployeeForm(request.POST)  
  4.         if form.is_valid():  
  5.             try:  
  6.                 return redirect('/')  
  7.             except:  
  8.                 pass  
  9.     else:  
  10.         form = EmployeeForm()  
  11.     return render(request,'index.html',{'form':form})  

Tuesday, December 13, 2022

How to define a function in python

 Defining a function in python is quit easy as c, c++, c#.

Here is the code how to define function in python.

def my_function(fname, lname):
  print(fname + " " + lname)

my_function("webhealer""Refsnes")

How to use For in python

 Like c, c#, c++ for loop sytax is very simple in python, see the below code how to use python.

name = ["web""healer ""blog"]
for in name:
  print(x)

Sunday, December 11, 2022

how to print a page using python

 printing current page using python is quit easy. we can use following code to do so.


def PrintOnePage(self, cp, pageNumber):
        """
        Print the current page on the given device context.

        Return true if there is still more to print.
        """
        self.currentPage = pageNumber
        self.CalculateBounds(cp)
        self.ApplyPageDecorations(cp)

        for a in self.runningBlocks:
            a.Print(cp)

        while len(self.blocks) and self.blocks[0].Print(cp):
            self.DropCurrentBlock()

        return len(self.blocks) > 0