This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now_app/settings.py | |
import os | |
BASE_DIR = os.path.dirname(os.path.dirname(os.abspath(__file__))) | |
# ... | |
STATIC_URL = '/static/' | |
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Django >=2.1,<2.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now-django-example/now_app/settings.py | |
# ... | |
ALLOWED_HOSTS = ['.now.sh'] # Allow *.now.sh | |
# ... | |
DATABASES = {} # Prevent Django from loading an adapter | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now-django-example/index.py | |
from now_app.wsgi import application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 2, | |
"name": "now-django-example", | |
"builds": [{ | |
"src": "now_app/wsgi.py", | |
"use": "@ardnt/now-python-wsgi", | |
"config": { "maxLambdaSize": "15mb" } | |
}], | |
"routes": [{ | |
"src": "/(.*)", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now-django-example/example_app/urls.py | |
from django.urls import path | |
from example.views import index | |
urlpatterns = [ | |
path('', index), | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now-django-example/example_app/views.py | |
from datetime import datetime | |
from django.http import HttpResponse | |
def index(request): | |
now = datetime.now() | |
html = f''' | |
<html> | |
<body> | |
<h1>Hello from Zeit Now!</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now-django-example/now_app/urls.py | |
from django.urls import path, include | |
urlpatterns = [ | |
# ... | |
path('', include('example_app.urls')), | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# now-django-example/now_app/settings.py | |
INSTALLED_APPS = [ | |
# ... | |
'example_app', | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple time quantizer for python. Takes in a time and gives back the | |
quantized time given resolution in seconds. Always rounds down. | |
""" | |
from datetime import datetime | |
def quantize_time(time, resolution): | |
"""Round a time object to the previous time appropriate for resolution""" |
NewerOlder