Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_shopify_app-2.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_shopify_app-2.1.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

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

Hashes for django_shopify_app-2.1.0.tar.gz
Algorithm Hash digest
SHA256 019f4d81e21371a4a9c74e0abc99fd6da8b5eff0be570c351afe54feef09db4e
MD5 28c9d4967ce4e83973f3437060a312b1
BLAKE2b-256 48a2ec9471ffca934e3d234e71cc96831def354d0fde92d758ee28d2a9f46a96

See more details on using hashes here.

File details

Details for the file django_shopify_app-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_shopify_app-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee9705a21291ebe63137ffb5be25a2d616aa2541520ccef14f7d53272126be13
MD5 e1a94675c44b65199aa29c297c066317
BLAKE2b-256 b1edac02de6d97267bd861bf04d56eae4d92c78644c70c5729bf6feada384a54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page