Skip to content

Moesif/moesifdjangoexample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moesif Django Example

Django is a web application framework that many developers use to serve APIs.

Moesif is an API analytics and monitoring platform. moesifdjango is a middleware that makes integration with Moesif easy for Django based applications.

This is an example of django application with Moesif integrated. This example is based on the quick start tutorials of Django and Django rest framework.

Key files

moesifdjango's github readme already documented the steps for setup Moesif Django. But here is the key file where the Moesif integration is added:

  • mysite/settings.py added Moesif middleware related settings.

How to run this example with WSGI

  1. Setup virtual env if needed python -m venv ENV. Start the virtual env by source ENV/bin/activate

  2. Install packages:

  • Django 3 LTS: pip install -r requirements.txt
  • Django 4: pip install -r requirements-django4.txt
  1. Be sure to edit the mysite/setting.py to add your Moesif application id.
MOESIF_MIDDLEWARE = {
    'APPLICATION_ID': 'Your Moesif Collector Application Id',
}

Your Moesif Collector Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Collector Application Id at any time by logging into the Moesif Portal, click on the bottom left user profile, and then clicking API Keys.

  1. Run the service:
python manage.py runserver
  1. See urls.py for some urls that you can hit the server with (e.g. http://localhost:8000/users), and the data should be captured in the corresponding Moesif account of the application id.

How to run this example with ASGI

  1. Setup virtual env if needed python -m venv ENV. Start the virtual env by source ENV/bin/activate

  2. Install packages:

  • Django 3 LTS: pip install -r requirements.txt
  • Django 4: pip install -r requirements-django4.txt

Also install dependencies to related to asgi

pip install --no-cache asgi uvicorn gunicorn
  1. Be sure to edit the mysite/setting.py to add your Moesif application id.
MOESIF_MIDDLEWARE = {
    'APPLICATION_ID': 'Your Moesif Collector Application Id',
}

Your Moesif Collector Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Collector Application Id at any time by logging into the Moesif Portal, click on the bottom left user profile, and then clicking API Keys.

  1. Run the service:
gunicorn mysite.asgi:application -k uvicorn.workers.UvicornWorker
  1. See urls.py for some urls that you can hit the server with (e.g. http://localhost:8000/users), and the data should be captured in the corresponding Moesif account of the application id.

Note : If you get OperationalError with Exception Value: no such table: auth_user, that means the schema has not been generated in database yet. please run the following command line to resolve

python manage.py migrate

Tested Python versions: 3.10.4
Tested Django versions: 3.2.13 (LTS), 4.0.5

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published