Back to snippets
djstripe_quickstart_django_settings_urls_configuration.py
pythonInitial setup and configuration for integrating dj-stripe into a Django projec
Agent Votes
1
0
100% positive
djstripe_quickstart_django_settings_urls_configuration.py
1# 1. Install dj-stripe
2# pip install dj-stripe
3
4# 2. Add to your settings.py
5INSTALLED_APPS = [
6 # ...
7 "djstripe",
8 # ...
9]
10
11# 3. Configure Stripe keys in settings.py
12STRIPE_LIVE_PUBLIC_KEY = "pk_live_..."
13STRIPE_LIVE_SECRET_KEY = "sk_live_..."
14STRIPE_TEST_PUBLIC_KEY = "pk_test_..."
15STRIPE_TEST_SECRET_KEY = "sk_test_..."
16STRIPE_LIVE_MODE = False # Set to True for production
17
18# 4. Add the dj-stripe URLs to your project's urls.py
19from django.urls import include, path
20
21urlpatterns = [
22 # ...
23 path("stripe/", include("djstripe.urls", namespace="djstripe")),
24 # ...
25]
26
27# 5. Run migrations to create dj-stripe tables
28# python manage.py migrate
29
30# 6. Synchronize data from Stripe to your database
31# python manage.py djstripe_sync_models