Live demo
Here you can find live demo of the Camera store sample application. This is the application we are going to build here.
Prerequisites
To follow along with this tutorial, you have to have:
- Active account in Tradenity
- Create the sample “Camera store”, and load the sample data (This option is available on the create store page).
- Have a working python development environment (python 2.7x installation, your IDE of choice)
- Basic familiarity with the Django framework.
Setup your credentials
First of all, you have to get API keys for your store, you can find it in your store Edit
page.
To get there navigate to the stores list page, click on the Edit
button next to your store name, scroll down till you find the API Keys
section.
Initialize the library
With the API key in hand, you can initialize the Tradenity client. Tradenity client needs the API key and an instance of AuthTokenHolder which is an object that makes Tradenity session integrates with the web framework’s (Django in our case) session mechanism. The SDK provide implementation for Django and it’s easy to implement youe own
You must initialize the library before making any API call. In a Django
application, you can put the initialization code
in wsgi.py
before calling application = get_wsgi_application()
method.
wsgi.py
from tradenity.sdk.ext.django.auth import DjangoAuthTokenHolder
from tradenity.sdk.http.client import Tradenity
Tradenity.initialize('sk_1234567', auth_token_holder=DjangoAuthTokenHolder)
Make sure to replace the api keys with the ones for your store, otherwise you will get authentication error
Introducing CameraStore sample application
CameraStore application is a typical e-store web application, a web store for a camera shop.
The project is distributed between 2 Django applications: accounts
, and camerastore
The application code is placed into camerastore
package, which is divided into these modules
camerastore/views/shop.py
: navigating the and browsing the store, the corresponding templates are in thecamerastore/templates
directory.vamerastore/views/cart.py
: Shopping cart manipulation code. the corresponding templatecamerastore/templates/cart.html
.accounts/views.py
: login management and registering new customers. the corresponding templates are in thecamerastore/templates/account
directory.camerastore/views/orders.py
: placing new order, viewing list and details of customer’s past orders. the corresponding templates are in thecamerastore/templates/orders
directory.