Filebase
Search…
Django
Learn how to configure Django for use with Filebase

What is Django?

Django is a Python web framework designed for rapid, highly-scalable development and deployment of web applications. Django offers a clean, pragmatic and secure design that enables developers to create web apps quickly and efficiently. Django is free and open source.
Read below to learn how to create a basic Django web app that communicates with your Filebase account and Filebase buckets.
This guide was written using Ubuntu 20.04. Commands may vary depending on your operating system.
This guide shows a sample configuration and how to connect a Django application to Filebase. Filebase is unable to provide debugging for custom applications due to their individualized nature.

Prerequisites:

  • Download and install Python3 on your operating system.
  • Download and install pip on your operating system.
  • Have Your Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Create a Filebase Bucket. Learn how to create a bucket here.

1. Install Django with the following command:

pip install django

2. Confirm the Django installation with the following command:

django-admin
This command will return a list of django core commands.

3. Create a new Django project with the following command:

django-admin startproject projectname
This command will create a Django project with the base level framework.

4. Navigate to the location of the manage.py file inside your project.

Your project’s directory will be a sub directory of where you ran the startproject command. In this example, the project is located at /home/filebase/testproject.

5. Run the following command to start the Django server:

python3 manage.py runserver

6. In a web browser, navigate to your Django server running athttp://127.0.0.1:8000.

You should see the following webpage:

7. Now you need to connect the Django project to Filebase.

Start by installing django-storages with the following command:
pip install django-storages

8. Next, install the boto3 library with the following command:

pip install boto3

9. Edit the settings.py file to include “storages” under the INSTALLED_APPS:

10. Configure the settings.py file to reflect your Filebase credentials and bucket information.

Add the following lines to the settings.py file, replacing values as necessary to match your configuration:
1
STATIC_ROOT = ‘static’
2
3
AWS_ACCESS_KEY_ID = 'Filebase-Access-Key'
4
AWS_SECRET_ACCESS_KEY = 'Filebase-Secret-Key'
5
AWS_STORAGE_BUCKET_NAME = 'Filebase-Bucket-Name'
6
AWS_S3_ENDPOINT_URL = 'https://s3.filebase.com'
7
8
AWS_S3_CUSTOM_DOMAIN = ‘%s.s3.filebase.com’ % AWS_STORAGE_BUCKET_NAME
9
10
AWS_LOCATION = ‘static’
11
12
STATICFILES_DORS = [
13
os.path.join(BASE_DIR, ‘randomsite/static’),
14
]
15
16
STATIC_URL = ‘https://%s/%s/’ % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
17
STATICFILES_STORAGE = ‘storages.backends.s3boto3.S3Boto3Storage’
Copied!

11. Run the following command to pull the static objects from your Filebase bucket:

python3 manage.py collectstatic
When prompted, enter ‘yes’. The output should resemble the following:

12. In your Filebase bucket there will be a new folder titled ‘Static’ that contains your Django project files.

From here, you can interact with the Filebase bucket from within your Django project.
If you have any questions, please send us an email at [email protected].
Last modified 11d ago