CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=a1f2449b3a04b9f9215a0758; HttpOnly; Path=/; Secure
set-cookie: trac_session=2de54f21964c0abfed50aa4a; expires=Tue, 21 Oct 2025 05:27:45 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 05:27:45 GMT
x-served-by: cache-fra-eddf8230164-FRA, cache-bom-vanm7210054-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753248465.885703,VS0,VE274
vary: Accept-Encoding
CookBookScriptsMiniFlush – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
This is for a old django Version?!?!?
Sick of running django-admin
repeatedly to init
your site and install
each of your apps when you've made lots of changes to the model? miniflush.py
will do all the heavy lifting for you:
import os from os.path import isdir, isfile, join, dirname import django.core.management, django.core def find_site(): """Find the site by looking at the environment.""" try: settings_module = os.environ['DJANGO_SETTINGS_MODULE'] except KeyError: raise AssertionError, "DJANGO_SETTINGS_MODULE not set." settingsl = settings_module.split('.') site = __import__(settingsl[0]) settings = __import__(settings_module, {}, {}, settingsl[-1]) return site, settings def delete_db(settings): """Delete the old database.""" engine = settings.DATABASE_ENGINE if engine == 'sqlite3': try: os.unlink(settings.DATABASE_NAME) except OSError: pass elif engine == 'mysql': import _mysql s = _mysql.connect(host=settings.DATABASE_HOST, user=settings.DATABASE_USER, passwd=settings.DATABASE_PASSWORD) for cmd in ['drop database if exists %s', 'create database %s']: s.query(cmd % settings.DATABASE_NAME) else: raise AssertionError, "Unknown database engine %s", engine def init_and_install(site): """Initialise the site and install any applications. Applications are found by looking for ``sitename/apps`` in sitename.apps.""" django.core.management.init() appdir = join(dirname(site.__file__), 'apps') for name in [name for name in os.listdir(appdir) if isdir(join(appdir, name)) and isfile(join(appdir, name, '__init__.py'))]: try: app = django.core.meta.get_app(name) django.core.management.install(app) except AttributeError, ex: pass # Exercise for reader: be more specific def main(): """Flush it all, baby!""" try: site, settings = find_site() delete_db(settings) init_and_install(site) except AssertionError, ex: print ex.args[0] if __name__ == '__main__': main()
Last modified
18 years ago
Last modified on Mar 16, 2007, 7:40:24 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.