DEV Community

Cover image for Host Your Own Online Shop with Django-Oscar & PyCharm
sarahmjohnson for AppMap

Posted on

Host Your Own Online Shop with Django-Oscar & PyCharm

Django-Oscar, the open-source ecommerce framework, sparked my interest as a Python/Django developer and a small business supporter because it allows developers to host their own online shops. The Django-Oscar framework “manages a 12 million item catalog supported by 100+ suppliers for a single project,” and provides the opportunity to customize the core functionality to support creative implementations. The ability to customize an implementation of an ecommerce framework is unique, as opposed to out-of-the-box ecommerce solutions like Shopify. Django-Oscar also has an extensive test suite and detailed documentation.

I use the ecommerce platforms, Etsy and Depop, to shop from small businesses, but the platforms take a high percentage of every sale, which causes price inflation and low returns. Using Django-Oscar to host an online marketplace for small businesses will lower the cost for buyers and sellers. I like that Django-Oscar already integrates with SAP web services, so for an online marketplace, business owners will update their inventory with no technical expertise needed.

Host Your Own Online Shop

The example site, also known as the “sandbox,” is the fastest way to get up and running with Django-Oscar. The documentation is found here. To get up and running, follow this workflow. Django-Oscar must be used in a virtual environment.

git clone https://github.com/django-oscar/django-oscar.git
cd django-oscar
virtualenv --python=python3 oscar
source ./oscar/bin/activate
make sandbox
sandbox/manage.py runserver
Enter fullscreen mode Exit fullscreen mode

The sandbox implementation is a bookstore. Navigate to the development server at http://127.0.0.1:8000/ and browse the marketplace.

Image description

Django-Oscar is a complex project with some key components you need to understand before customizing an implementation. The documentation for Oscar is great, but I am a visual learner. I like to see the end-to-end flow of a project before jumping in.

I use AppMap, an open source dynamic application analysis tool, to visually understand how applications operate at runtime. AppMap records your applications’ runtime code behavior by watching your test cases running, or by seeing how your application runs locally, in Docker, or in a development environment. The AppMaps will include data about your application like function calls, HTTP request attributes, authentication, authorization, SQL queries and more.

The result is a complete picture showing exactly the path the code takes as it executes. From API request to the database - AppMap displays all the packages, classes, and functions involved in the request.

For example, the image below shows the Dependency Map for a POST request to the /checkout/ endpoint in Django-Oscar.

Image description

Install AppMap

To install AppMap, add it as a plugin for PyCharm.

Image description

Next, add AppMap to the Django-Oscar repo with the click of a button in PyCharm or via the CLI.

Image description

AppMap will add a configuration file, appmap.yml, which will enable request recording by default. A new AppMap will be generated with each request you make in Django-Oscar.

Generate AppMaps

With AppMap recording enabled, restart the Django-Oscar development server and begin to interact with the application. AppMaps will appear instantly in PyCharm!

Image description

Click on one of the AppMaps in PyCharm to open it and then select “Trace View” and navigate through the function calls. You will see the HTTP requests, function calls, and SQL queries that were generated from your application interactions.

Image description

Expand the child nodes to see the entire trace.

Image description

As you interact with the application, more AppMaps will be generated. Dig into the Dependency Maps and Trace Views for these interactions to strengthen your understanding.

Summary

At this point, you have Django-Oscar and AppMap up and running locally in PyCharm. Once you understand how Django-Oscar works, customize your implementation to meet the needs of your online shop and host your application!

In part 2 of this post, you will learn how to run tests locally on
Django-Oscar. With AppMap installed, you’ll automatically record those test cases running and generate maps.

If you are interested in learning more, join the conversation and chat with other AppMap engineers and users by joining the AppMap community Slack.

Top comments (0)