Django Integration

Integrating the GoodGrids API with a Django application is very simple. The official django-goodgrids API is available to make this painless.

Install django-goodgrids

These integrations require the django-goodgrids API. You can install it by running

pip install django-goodgrids

You can also add django-goodgrids to the requirements.pip file in your project to make sure that this API library gets installed.


Using GoodGrids with class-based views

Let's assume your Django application already has a class-based view DownloadDataCSVView that returns a CSV file for your users to download. To create a view that let's your users download Excel files, use the following snippet:

from django_goodgrids.views import DownloadDataAsExcelView

class DownloadDataAsExcelView(GoodGridsExcelExportViewMixin, DownloadDataCSVView):
    goodgrids_api_url = 'https://goodgrids.com/create-excel-file/3a6c0d9ac7c74d'
    excel_file_name = 'data.xlsx'

Make sure to set goodgrids_api_url to your actual API URL.

You can then include this in your urls.py:

url(r'^download-data-as-excel-file/?$',
    views.DownloadDataAsExcelView.as_view(),
    name='download_data_as_excel_file'),

Using Goodgrids with function-based views

Let's assume your Django application already has a function-based view named download_data_as_csv_view that returns a CSV file for your users to download. To create a view that let's your users download Excel files, use the following snippet:

from django_goodgrids.views import create_goodgrids_excel_export_view

download_data_as_excel_view = create_goodgrids_excel_export_view(
    csv_export_view=download_data_as_csv_view,
    goodgrids_api_url='https://goodgrids.com/create-excel-file/3a6c0d9ac7c74d',
    excel_file_name='data.xlsx',
)

Make sure to set goodgrids_api_url to your actual API URL.

You can then include this in your urls.py:

url(r'^download-data-as-excel-file/?$',
    views.download_data_as_excel_view,
    name='download_data_as_excel_file'),

Generic Python

You can also integrate the GoodGrids API into your python application manually.

Found a bug? Have a suggestion on how to improve this documentation? Please send us a note at support@goodgrids.com.

Print