A django app with all the tools required to make a Shopify app
Project description
django-shopify-app
Add the app in settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'shopify_app',
'shops',
]
Add the required configurations in settings.py
SHOPIFY_API_KEY = config('SHOPIFY_API_KEY')
SHOPIFY_API_SECRET = config('SHOPIFY_API_SECRET')
SHOPIFY_APP_SCOPES = [
'read_products',
'read_orders',
]
SHOPIFY_WEBHOOK_TOPICS = [
'products/update',
'app/uninstalled',
]
SHOPIFY_SHOP_MODEL = 'shops.Shop'
SHOPIFY_WEBHOOK_HOST = 'https://moship.ngrok.io'
SHOPIFY_APP_HOST = 'https://moship.ngrok.io'
SHOPIFY_WEBHOOK_CALLBACK = 'shops.webhooks.webhook_entry'
SHOPIFY_GDPR_WEBHOOK_CALLBACK = 'shops.webhooks.webhook_entry'
Create a path to init the access token request and another path to end the token request
from django.urls import path
from shopify_app.views import InitTokenRequestView, EndTokenRequestView
app_name = 'my_shopify_app'
urlpatterns = [
path(
'login-online/',
InitTokenRequestView.as_view(
redirect_path_name='my_shopify_app:end-token-request',
),
),
path(
'confirm/',
EndTokenRequestView.as_view(
redirect_path_name='embed_admin:dashboard',
),
name='end-token-request'
),
]
Add the url patterns for the app
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('shopify/', include('shopify_app.urls')),
]
ShopSessionMixin
A mixin that authenticates requests against a valid Shopify shop session (JWT). Use it with any APIView or DRF generic view:
from rest_framework.views import APIView
from shopify_app.mixins import ShopSessionMixin
class MyView(ShopSessionMixin, APIView):
def get(self, request, *args, **kwargs):
shop = request.shop
...
Staff bypass
Staff users can skip Shopify JWT validation if they have a shop associated with their user model. Enable it globally in settings:
SHOPIFY_STAFF_BYPASS = True # Default: False
SHOPIFY_STAFF_SHOP_ATTR = 'admin_shop' # Default: 'admin_shop'
Or per-view:
class MyView(ShopSessionMixin, APIView):
allow_staff_bypass = True # Overrides the global setting
When enabled, if the request user is authenticated, is staff, and has a truthy value on the configured attribute (admin_shop by default), the mixin sets request.shop from that attribute and skips JWT validation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_shopify_app-2.1.0.tar.gz.
File metadata
- Download URL: django_shopify_app-2.1.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
019f4d81e21371a4a9c74e0abc99fd6da8b5eff0be570c351afe54feef09db4e
|
|
| MD5 |
28c9d4967ce4e83973f3437060a312b1
|
|
| BLAKE2b-256 |
48a2ec9471ffca934e3d234e71cc96831def354d0fde92d758ee28d2a9f46a96
|
File details
Details for the file django_shopify_app-2.1.0-py3-none-any.whl.
File metadata
- Download URL: django_shopify_app-2.1.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee9705a21291ebe63137ffb5be25a2d616aa2541520ccef14f7d53272126be13
|
|
| MD5 |
e1a94675c44b65199aa29c297c066317
|
|
| BLAKE2b-256 |
b1edac02de6d97267bd861bf04d56eae4d92c78644c70c5729bf6feada384a54
|