Created
October 16, 2016 19:48
-
-
Save seanbehan/b28ae7a9819026689eac2137e9aba331 to your computer and use it in GitHub Desktop.
using django-micro for small django sites
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
# | |
# pip install django-micro | |
# | |
# *make sure the label for model meta property is set to the name of current directory* | |
# | |
# python app.py makemigrations | |
# python app.py migrate | |
# python app.py runserver | |
# | |
import os | |
from django_micro import configure, route, run | |
from django.http import HttpResponse | |
from django.db import models | |
DEBUG = True | |
STATIC_URL = '/static/' | |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
INSTALLED_APPS = [ | |
'django.contrib.admin', | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
] | |
DEBUG = True | |
CONTEXT_PROCESSORS = [ | |
'django.template.context_processors.debug', | |
'django.template.context_processors.request', | |
'django.contrib.auth.context_processors.auth', | |
'django.contrib.messages.context_processors.messages', | |
] | |
MIDDLEWARE = [ | |
'django.middleware.security.SecurityMiddleware', | |
'django.contrib.sessions.middleware.SessionMiddleware', | |
'django.middleware.common.CommonMiddleware', | |
'django.middleware.csrf.CsrfViewMiddleware', | |
'django.contrib.auth.middleware.AuthenticationMiddleware', | |
'django.contrib.messages.middleware.MessageMiddleware', | |
'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
] | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', | |
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | |
}, | |
} | |
configure(locals()) | |
class Post(models.Model): | |
title = models.CharField(max_length=255) | |
class Meta: | |
app_label = 'example' | |
@route(r'^$', name='index') | |
def show_index(request): | |
name = request.GET.get('name', 'World') | |
return HttpResponse('Hello, {}!'.format(name)) | |
application = run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment