Skip to content

Commit

Permalink
[python/django] remove use of "builds" (#905)
Browse files Browse the repository at this point in the history
### Description

We don't want to encourage the use of `builds` in `vercel.json`. This PR
updates the `python/django` example to not use `builds`.

I tested manually deploying this example and it worked for me.

### Demo URL

https://django-qqienvle1-uncurated-tests.vercel.app/

### Type of Change

- [ ] New Example
- [x] Example updates (Bug fixes, new features, etc.)
- [ ] Other (changes to the codebase, but not to examples)
  • Loading branch information
EndangeredMassa committed Apr 12, 2024
1 parent 389a044 commit fe3844e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 25 deletions.
18 changes: 9 additions & 9 deletions python/django/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ https://django-template.vercel.app/

## How it Works

Our Django application, `example` is configured as an installed application in `vercel_app/settings.py`:
Our Django application, `example` is configured as an installed application in `api/settings.py`:

```python
# vercel_app/settings.py
# api/settings.py
INSTALLED_APPS = [
# ...
'example',
Expand All @@ -23,22 +23,22 @@ INSTALLED_APPS = [
We allow "\*.vercel.app" subdomains in `ALLOWED_HOSTS`, in addition to 127.0.0.1:

```python
# vercel_app/settings.py
# api/settings.py
ALLOWED_HOSTS = ['127.0.0.1', '.vercel.app']
```

The `wsgi` module must use a public variable named `app` to expose the WSGI application:

```python
# vercel_app/wsgi.py
# api/wsgi.py
app = get_wsgi_application()
```

The corresponding `WSGI_APPLICATION` setting is configured to use the `app` variable from the `vercel_app.wsgi` module:
The corresponding `WSGI_APPLICATION` setting is configured to use the `app` variable from the `api.wsgi` module:

```python
# vercel_app/settings.py
WSGI_APPLICATION = 'vercel_app.wsgi.app'
# api/settings.py
WSGI_APPLICATION = 'api.wsgi.app'
```

There is a single view which renders the current time in `example/views.py`:
Expand Down Expand Up @@ -77,10 +77,10 @@ urlpatterns = [
]
```

Finally, it's made accessible to the Django server inside `vercel_app/urls.py`:
Finally, it's made accessible to the Django server inside `api/urls.py`:

```python
# vercel_app/urls.py
# api/urls.py
from django.urls import path, include

urlpatterns = [
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ASGI config for vercel_app project.
ASGI config for api project.
It exposes the ASGI callable as a module-level variable named ``application``.
Expand All @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vercel_app.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings')

application = get_asgi_application()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for vercel_app project.
Django settings for api project.
Generated by 'django-admin startproject' using Django 4.1.3.
Expand Down Expand Up @@ -50,7 +50,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'vercel_app.urls'
ROOT_URLCONF = 'api.urls'

TEMPLATES = [
{
Expand All @@ -68,7 +68,7 @@
},
]

WSGI_APPLICATION = 'vercel_app.wsgi.app'
WSGI_APPLICATION = 'api.wsgi.app'


# Database
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""vercel_app URL Configuration
"""api URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
WSGI config for vercel_app project.
WSGI config for api project.
It exposes the WSGI callable as a module-level variable named ``app``.
Expand All @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vercel_app.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings')

app = get_wsgi_application()
2 changes: 1 addition & 1 deletion python/django/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vercel_app.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
8 changes: 1 addition & 7 deletions python/django/vercel.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"builds": [
{
"src": "vercel_app/wsgi.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "vercel_app/wsgi.py"
"dest": "api/wsgi.py"
}
]
}

0 comments on commit fe3844e

Please sign in to comment.