Skip to content

Instantly share code, notes, and snippets.

@qwIvan
Forked from seanbehan/app.py
Created March 26, 2018 09:15
Show Gist options
  • Save qwIvan/eda46da75e674c7f279c5e42ad9a2783 to your computer and use it in GitHub Desktop.
Save qwIvan/eda46da75e674c7f279c5e42ad9a2783 to your computer and use it in GitHub Desktop.

Revisions

  1. @seanbehan seanbehan revised this gist Jul 13, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,9 @@
    python manage.py makemigrations
    python manage.py migrate
    DJANGO_SETTINGS_MODULE=settings python app.py
    visit http://localhost:5000
    See https://docs.djangoproject.com/en/1.11/topics/settings/#either-configure-or-django-settings-module-is-required for documentation
    '''

    from flask import Flask
  2. @seanbehan seanbehan revised this gist Jul 13, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    mv models.py app/
    python manage.py makemigrations
    python manage.py migrate
    python app.py
    DJANGO_SETTINGS_MODULE=settings python app.py
    '''

    from flask import Flask
  3. @seanbehan seanbehan revised this gist Jul 13, 2017. 2 changed files with 6 additions and 5 deletions.
    4 changes: 4 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    '''
    Run the following commands (bc. gists don't allow directories)
    pip install flask django dj-database-url psycopg2
    mkdir -p app/migrations
    touch app/__init__.py app/migrations/__init__.py
    @@ -7,6 +10,7 @@
    python manage.py migrate
    python app.py
    '''

    from flask import Flask
    from django.apps import apps
    from django.conf import settings
    7 changes: 2 additions & 5 deletions settings.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,7 @@
    import dj_database_url

    DATABASES = {}
    DATABASES['default'] = dj_database_url.config(default='postgres://localhost/py_example_app')
    DATABASES = { 'default': dj_database_url.config(default='postgres://localhost/py_example_app') }

    INSTALLED_APPS = (
    'app',
    )
    INSTALLED_APPS = ( 'app', )

    SECRET_KEY = 'REPLACE_ME'
  4. @seanbehan seanbehan created this gist Jul 13, 2017.
    25 changes: 25 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    '''
    mkdir -p app/migrations
    touch app/__init__.py app/migrations/__init__.py
    mv models.py app/
    python manage.py makemigrations
    python manage.py migrate
    python app.py
    '''
    from flask import Flask
    from django.apps import apps
    from django.conf import settings

    apps.populate(settings.INSTALLED_APPS)

    from app.models import Hit

    app = Flask(__name__)

    @app.route("/")
    def index():
    return str(Hit.objects.count())

    if __name__=='__main__':
    app.run(debug=True)
    7 changes: 7 additions & 0 deletions manage.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    #!/usr/bin/env python
    import os, sys

    if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)
    15 changes: 15 additions & 0 deletions models.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    from django.db import models
    from django.contrib.postgres.fields import JSONField

    class BaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True, null=True)
    updated_at = models.DateTimeField(auto_now=True, null=True)

    def attributes(self):
    return self.__dict__

    class Meta:
    abstract = True

    class Hit(BaseModel):
    data = JSONField(null=True)
    10 changes: 10 additions & 0 deletions settings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import dj_database_url

    DATABASES = {}
    DATABASES['default'] = dj_database_url.config(default='postgres://localhost/py_example_app')

    INSTALLED_APPS = (
    'app',
    )

    SECRET_KEY = 'REPLACE_ME'