Hacker News new | ask | show | jobs
by shanebellone 1218 days ago
Flask FTW.
1 comments

If you like Flask (I do too), you can do what we used to do before Flask existed (./djngo.com -p project runserver) where .python/project.py in the zip is:

  import os
  from django.conf import settings
  from django.core import management
  from django.conf.urls import url
  from django.http import HttpResponse

  # Django 2.2 Release Notes
  # https://docs.djangoproject.com/en/4.1/releases/2.2/
  # Documentation
  # https://docs.djangoproject.com/en/2.2/

  __version__ = 0.1

  DEBUG = True
  ROOT_URLCONF = 'project'
  DATABASES = {'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'project.db' }}
  SECRET_KEY = os.getenv('SECRET_KEY', 'Please set a SECRET_KEY as an env var.')

  if not settings.configured:
    settings.configure(**locals())

  def index(request):
    return HttpResponse('Hello Django!')

  urlpatterns = [
    url(r'^$', index),
  ]

  if __name__ == '__main__':  # pragma: no cover
    management.execute_from_command_line()
The problem with Django is all the things that make it Django. Frankly, I'd build my own Flask from scratch, but I can't find a good excuse.

With that being said, I hadn't thought much about "before Flask". I very well might feel differently if I had been coding then.