Posts

Install Python 3 virtualenv on Ubuntu

# Step 1: Update your repositories sudo apt-get update # Step 2: Install pip for Python 3 sudo apt-get install build-essential libssl-dev libffi-dev python-dev sudo apt install python3-pip # Step 3: Use pip to install virtualenv sudo pip3 install virtualenv # Step 4: Launch your Python 3 virtual environment, here the name of my virtual environment will be env3 virtualenv -p python3 env3 # Step 5: Activate your new Python 3 environment. There are two ways to do this . env3/bin/activate # or source env3/bin/activate which does exactly the same thing # you can make sure you are now working with Python 3 python -- version # this command will show you what is going on: the python executable you are using is now located inside your virtualenv repository which python # Step 6: code your stuff # Step 7: done? leave the virtual environment deactivate

How to create virtual host with wildcard in apache server using ubuntu

1.) Start by copying the file for the first domain:-  sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/ demo.com .conf 2.) Open the new file in your editor with root privileges sudo gedit /etc/apache2/sites-available/ demo .com .conf 3.) Remove the all constant from the file and replace the below text <VirtualHost *:80>     ServerAdmin demo@example.com     ServerName demo.com     ServerAlias www.demo.com     DocumentRoot /var/www/html/php-work/wordpress     ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>  4.) We can use the a2ensite tool to enable each of our sites like this sudo a2ensite demo.com .conf 5.) Set the local host and restart server sudo nano /etc/hosts 127.0.0.1 demo.com sudo service apache2 restart   for wildcard setup 1.) sudo apt-get install dnsmasq 2.) sudo service network-manager restart 3.) sudo gedit dnsmasq.conf 4.) include the line #a

Strip Integration

// $p=\Stripe\Customer::create(array(             //   "email" => " sneha.unified17@gmail.com ",             //   "description" => "Employess"             // ));             // print_r($p);             //  $account = \Stripe\Customer::retrieve(" cus_A8N9jIROdxw0VZ");             //  print_r($account->sources);             // $myCard = array('number' => '5200828282828210', 'exp_month' => 8, 'exp_year' => 2018);             // $charge = \Stripe\Charge::create(array(' card' => $myCard, 'amount' => 1000, 'currency' => 'usd'));             // print_r($charge);             // $charge = \Stripe\Charge::create(array(             //     "amount" => '100',             //     "currency" => "usd",             //     "customer" => 'cus_A8N9jIROdxw0VZ',            

How to install Laravel in Linux

1.)  Go to your Root directory by CLI (Command line interface). 2.)  We have to need "PHP mcrypt" extension module be enabled. To enable it, run this command in the terminal.           sudo php5enmod mcrypt after that restart the Apache web server to load the mcrypt module:     sudo service apache2 restart to check if mcrypt is enabled or not:     php -m | grep mcrypt 3.) Go to your WebRoot direcory (var/www/html) and run this command in terminal     sudo curl -sS https://getcomposer.org/installer | sudo php         sudo mv composer.phar /usr/local/bin/composer     curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer 4.)Finally, we are ready to actually install the Laravel framework, after completing these steps. composer create-project laravel/laravel laravel --prefer-dist 5.) copy all files of public folder and paste out side of public folder , after that Open the index.php in the laravel folder in a text editor and rep

How to import data from csv/xls file in database using python django

def import_data(request):     log_message= None     if request.method == 'POST':         file_name=request.FILES['csv_file'].name         fname=str(time.time())+'-'+file_name         handle_uploaded_file( request.FILES['csv_file'] , 'upload/'+fname)         with open('upload/'+fname) as csvfile:          reader = csv.DictReader(csvfile)          for row in reader:              p = Product( product_name=row['product_name'], price=row['price'], content_text=row['content_text'] )              p.save()         log_message = 'Data has been successfully added'     product_list = Product.objects.order_by('-pub_date')     context = {'product_list': product_list , 'message': log_message}     return render(request,'administrator/dashboard.html',context) def handle_uploaded_file(f,fnam):     destination = open(fnam, 'wb+')     for chunk in f.

How to export data in xls format using python django

   import xlwt     import datetime , time     file_name = 'Expense-duplicate-'+str(int(round(time.time() * 1000)))+'.xls'     Duplicate = AvOutExpDashDuplicate.objects.values('e_employee_number','report_owner_id').order_by()[:5]     todo_obj=Duplicate     response = HttpResponse(content_type='application/ms-excel')     response['Content-Disposition'] = 'attachment; filename=%s' %(file_name)     wb = xlwt.Workbook(encoding='utf-8')     ws = wb.add_sheet("Todo")     row_num = 0     columns = [ (u"Employee Number", 4000), (u"Report ID", 8000), ]     font_style = xlwt.XFStyle()     font_style.font.bold = True     for col_num in xrange(len(columns)):         ws.write(row_num, col_num, columns[col_num][0], font_style)         # set column width         ws.col(col_num).width = columns[col_num][1]     font_style = xlwt.XFStyle()     font_style.alignment.wrap = 1  

How to export data in csv format using python django

import djqscsv Duplicate=AvOutExpDashDuplicate.objects.values('e_employee_number','report_owner_id').order_by()[:5] return djqscsv.render_to_csv_response(Duplicate)