Skip to content

Commit

Permalink
enhance base and home page
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-101 committed Jul 25, 2024
1 parent 0830d5c commit 4aab51f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
57 changes: 45 additions & 12 deletions djstripe_example/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
{% get_current_language as LANGUAGE_CODE %}
<html lang="{{ LANGUAGE_CODE }}" data-bs-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Dj-Stripe Example Project">
<meta name="author" content="Abe Hanoka">
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Dj-Stripe Example Project" />
<meta name="author" content="Abe Hanoka" />
<meta name="keywords"
content="Dj-Stripe, Stripe, Django, Payment Integration">
<title>Dj-Stripe Example Project</title>
<script src="https://js.stripe.com/v3/"></script>
<link rel="stylesheet" href="https://unpkg.com/mvp.css">
content="Dj-Stripe, Stripe, Django, Payment Integration" />
<title>
{% block title %}
Dj-Stripe Example Project
{% endblock title %}
</title>
{% block css %}
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css"
integrity="sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg=="
crossorigin="anonymous"
referrerpolicy="no-referrer" />
<!-- Bootstrap Icons -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css"
integrity="sha512-dPXYcDub/aeb08c63jRq/k6GaKccl256JQy/AnOq7CAnEZ9FzSL9wSbcZkMp4R26vBsMLFYH4kQ67/bbV8XaCQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer" />
{% endblock css %}
{% block javascript %}
<!-- Stripe JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.bundle.min.js"
integrity="sha512-7Pi/otdlbbCR+LnW+F7PwFcSDJOuUJB3OxtEHbg4vSMvzvJjde4Po1v4BR9Gdc9aXNUNFVUY+SK51wWT8WF0Gg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"></script>
<script src="https://js.stripe.com/v3/"></script>
{% endblock javascript %}
</head>
<body>
{% block content %}
{% endblock content %}
<body class="{% block bodyclass %}{% endblock bodyclass %}">
{% block body %}
<div class="container mt-4">
{% block content %}
{% endblock content %}
</div>
{% endblock body %}
{% block inline_javascript %}
{% endblock inline_javascript %}
</body>
</html>
18 changes: 18 additions & 0 deletions djstripe_example/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block title %}
Home - Dj-Stripe Example Project
{% endblock title %}
{% block content %}
<div class="container mt-5">
<div class="row">
<div class="col-md-12 text-center">
<h1 class="mb-4">Welcome to Dj-Stripe Example Project</h1>
<p class="lead mb-4">Easily integrate Stripe with your Django application.</p>
<a href="{% url 'create_checkout_session' %}"
class="btn btn-primary btn-lg">
<i class="bi bi-cart"></i> Start Checkout
</a>
</div>
</div>
</div>
{% endblock content %}
3 changes: 3 additions & 0 deletions djstripe_example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

from django.contrib import admin
from django.urls import include, path
from django.views.generic import TemplateView


from .views import checkout_redirect, create_checkout_session, checkout_session_success

urlpatterns = [
path("", TemplateView.as_view(template_name="home.html"), name="home"),
path("admin/", admin.site.urls),
path(
"checkout/redirect/<str:session_id>",
Expand Down
6 changes: 4 additions & 2 deletions djstripe_example/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

def get_or_create_starter_price():
try:
product = Product.objects.get(metadata__djstripe_example="example_subscription")
product = Product.objects.filter(
metadata__djstripe_example="example_subscription"
).first()
except Product.DoesNotExist:
print("Could not find a subscription product to use. Will create one for you.")
stripe_product = stripe.Product.create(
Expand All @@ -23,7 +25,7 @@ def get_or_create_starter_price():
product = Product.sync_from_stripe_data(stripe_product)

try:
return Price.objects.get(metadata__djstripe_example="starter_price")
return Price.objects.filter(metadata__djstripe_example="starter_price").first()
except Price.DoesNotExist:
print("Could not find a subscription price to use. Will create one for you.")
stripe_price = stripe.Price.create(
Expand Down

0 comments on commit 4aab51f

Please sign in to comment.