<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: muzu-85</title>
    <description>The latest articles on DEV Community by muzu-85 (@muzammil85).</description>
    <link>https://dev.to/muzammil85</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F924628%2Fd024a761-a3f5-4132-aeb9-6c78ec41995b.jpeg</url>
      <title>DEV Community: muzu-85</title>
      <link>https://dev.to/muzammil85</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muzammil85"/>
    <language>en</language>
    <item>
      <title>Integrating Razorpay with Django: A Step-by-Step Guide</title>
      <dc:creator>muzu-85</dc:creator>
      <pubDate>Mon, 17 Jul 2023 05:57:02 +0000</pubDate>
      <link>https://dev.to/muzammil85/integrating-razorpay-with-django-a-step-by-step-guide-2gdi</link>
      <guid>https://dev.to/muzammil85/integrating-razorpay-with-django-a-step-by-step-guide-2gdi</guid>
      <description>&lt;p&gt;Razorpay is a popular payment gateway solution that enables seamless online transactions. If you're developing a Django project and looking to integrate Razorpay as the payment gateway, this step-by-step guide will walk you through the process. By following these instructions, you'll be able to seamlessly incorporate Razorpay into your Django web application and start accepting payments in no time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before you begin, make sure you have a Razorpay account. If you haven't signed up yet, head over to &lt;a href="https://razorpay.com/"&gt;https://razorpay.com/&lt;/a&gt; and create an account. Once you have your account, you're ready to proceed with the integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Install the Razorpay Package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by installing the Razorpay Python package in your Django project. Open your terminal or command prompt and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install razorpay
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Set Up the Integration Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your Django project, create a new directory called 'razorpay_integration' (or any other name of your choice) inside your app directory. This directory will house the integration code. Within the 'razorpay_integration' directory, create a new file called 'razorpay_integration.py'.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Initialize the Razorpay Client&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the 'razorpay_integration.py' file, import the necessary modules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import razorpay
from django.conf import settings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, initialize the Razorpay client with your API credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client = razorpay.Client(auth=(settings.RAZORPAY_API_KEY, settings.RAZORPAY_API_SECRET))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Create a Payment Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Define a function to initiate a payment. This function will handle the creation of a Razorpay order and return the order ID. Feel free to customize this function according to your project's requirements. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def initiate_payment(amount, currency='INR'):
   data = {
       'amount': amount * 100,  # Razorpay expects amount in paise (e.g., 100 INR = 10000 paise)
       'currency': currency,
       'payment_capture': '1'  # Auto capture the payment after successful authorization
   }
   response = client.order.create(data=data)
   return response['id']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Create a Payment View&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Build a Django view that calls the 'initiate_payment' function and renders a payment page with the order ID. Customize the view according to your project's needs. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.shortcuts import render

def payment_view(request):
   amount = 100  # Set the amount dynamically or based on your requirements
   order_id = initiate_payment(amount)
   context = {
       'order_id': order_id,
       'amount': amount
   }
   return render(request, 'payment.html', context)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Design the Payment Page&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a template file called 'payment.html' to display the payment page. Utilize Razorpay's JavaScript code to handle the payment form submission. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://checkout.razorpay.com/v1/checkout.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;form action="{% url 'payment_success' %}" method="POST"&amp;gt;
   &amp;lt;input type="hidden" name="order_id" value="{{ order_id }}"&amp;gt;
   &amp;lt;script&amp;gt;
       var options = {
           "key": "{{ settings.RAZORPAY_API_KEY }}",
           "amount": "{{ amount }}",
           "currency": "INR",
           "name": "Your Company Name",
           "description": "Payment Description",
           "order_id": "{{ order_id }}",
           "handler": function(response) {
               // Handle the payment success response
               // You can submit the form or redirect to a success page
               document.forms[0].submit();
           },
           "prefill": {
               "name": "John Doe",
               "email": "john@example.com",
               "contact": "9876543210"
           }
       };
       var rzp = new Razorpay(options);
       rzp.open();
   &amp;lt;/script&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7: Handle the Payment Success Callback&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create another Django view to handle the payment success callback. This view will verify the payment status and perform any necessary actions. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def payment_success_view(request):
   order_id = request.POST.get('order_id')
   payment_id = request.POST.get('razorpay_payment_id')
   signature = request.POST.get('razorpay_signature')
   params_dict = {
       'razorpay_order_id': order_id,
       'razorpay_payment_id': payment_id,
       'razorpay_signature': signature
   }
   try:
       client.utility.verify_payment_signature(params_dict)
       # Payment signature verification successful
       # Perform any required actions (e.g., update the order status)
       return render(request, 'payment_success.html')
   except razorpay.errors.SignatureVerificationError as e:
       # Payment signature verification failed
       # Handle the error accordingly
       return render(request, 'payment_failure.html')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 8: Update URLs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modify your Django project's URLs to include the new views. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.urls import path
from .views import payment_view, payment_success_view

urlpatterns = [
   path('payment/', payment_view, name='payment'),
   path('payment/success/', payment_success_view, name='payment_success'),
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You've successfully integrated Razorpay with your Django project. By following this step-by-step guide, you can now accept payments seamlessly within your web application. &lt;br&gt;
Remember to replace 'settings.RAZORPAY_API_KEY' and 'settings.RAZORPAY_API_SECRET' with your actual Razorpay API key and secret in the code. Now you're all set to provide your users with a smooth and secure payment experience. &lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>django</category>
      <category>razorpay</category>
      <category>payment</category>
      <category>backend</category>
    </item>
    <item>
      <title>Django for newbeeez</title>
      <dc:creator>muzu-85</dc:creator>
      <pubDate>Sat, 18 Mar 2023 16:55:45 +0000</pubDate>
      <link>https://dev.to/muzammil85/django-for-newbeeez-33j3</link>
      <guid>https://dev.to/muzammil85/django-for-newbeeez-33j3</guid>
      <description>&lt;p&gt;let's explore some django !!!!!!&lt;/p&gt;

&lt;p&gt;this is a beginner friendly tutorial&lt;/p&gt;

&lt;p&gt;so what is django?&lt;/p&gt;

&lt;p&gt;actually,&lt;/p&gt;

&lt;p&gt;Django is a powerful web framework that makes building web applications easy and efficient. It is written in Python, and it follows the Model-View-Controller (MVC) architectural pattern. In this tutorial, we will walk through the basics of Django and build a simple web application.&lt;/p&gt;

&lt;p&gt;lets dive into it -&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Installing Django&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we start building our application, we need to install Django. We can do this by running the following command in our terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install Django
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Creating a Django Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once Django is installed, we can create our first Django project by running the following command in our terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;django-admin startproject myproject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory called myproject that contains the basic structure of a Django project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Creating a Django App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to create a Django app within our project. We can do this by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py startapp myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory called myapp that contains the basic structure of a Django app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Creating a Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Django, a model is a representation of a database table. We can define our model in the models.py file within our app directory. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.db import models

class MyModel(models.Model):
    name = models.CharField(max_length=100)
    email = models.EmailField()
    message = models.TextField()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sure, here's a beginner-friendly tutorial on Django.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Creating a View&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Django, a view is a function that handles HTTP requests and returns an HTTP response. We can define our view in the views.py file within our app directory. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.shortcuts import render
from .models import MyModel

def index(request):
    if request.method == 'POST':
        name = request.POST['name']
        email = request.POST['email']
        message = request.POST['message']
        MyModel.objects.create(name=name, email=email, message=message)
    return render(request, 'index.html')

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This view defines a function called index that handles HTTP requests. If the request is a POST request, it creates a new record in the MyModel table with the data submitted in the form. Finally, it returns a rendered template called index.html.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Creating a Template&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Django, a template is a file that defines the structure and layout of a web page. We can define our template in the templates directory within our app directory. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;My App&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;My App&amp;lt;/h1&amp;gt;
    &amp;lt;form method="post"&amp;gt;
        {% csrf_token %}
        &amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
        &amp;lt;input type="text" id="name" name="name"&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
        &amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
        &amp;lt;input type="email" id="email" name="email"&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
        &amp;lt;label for="message"&amp;gt;Message:&amp;lt;/label&amp;gt;
        &amp;lt;textarea id="message" name="message"&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
        &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This template defines an HTML form that allows users to submit their name, email, and message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: Connecting Everything Together&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, we need to connect everything together. We can do this by defining our URLs in the urls.py file within our app directory. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This URL pattern maps the root URL ('') to the index view defined in views.py.&lt;/p&gt;

&lt;p&gt;Next, we need to include our app's URLs in the project's URLs. We can do this by adding the following line to the urls.py file within our project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;path('', include('myapp.urls')),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line includes the URLs defined in myapp.urls within the project's URLs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Running the Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have everything set up, we can run the server by running the following command in our terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py runserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start the server on &lt;code&gt;http://127.0.0.1:8000/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9: Testing the Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open your browser and go to &lt;code&gt;http://127.0.0.1:8000/&lt;/code&gt;. You should see the form we created in the template. Fill out the form and submit it. If everything is working correctly, you should see a new record in the MyModel table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we walked through the basics of Django and built a simple web application. We learned how to create a project, create an app, define a model, define a view, create a template, connect everything together with URLs, and run the server. With this foundation, you can continue to explore Django and build more complex web applications.&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
