1 from django
.core
.management
.base
import BaseCommand
3 from optparse
import make_option
5 class Command(BaseCommand
):
6 option_list
= BaseCommand
.option_list
+ (
7 make_option('--noinput', action
='store_false', dest
='interactive', default
=True,
8 help='Tells Django to NOT prompt the user for input of any kind.'),
9 make_option('--addrport', action
='store', dest
='addrport',
10 type='string', default
='',
11 help='port number or ipaddr:port to run the server on'),
12 make_option('--ipv6', '-6', action
='store_true', dest
='use_ipv6', default
=False,
13 help='Tells Django to use a IPv6 address.'),
15 help = 'Runs a development server with data from the given fixture(s).'
16 args
= '[fixture ...]'
18 requires_model_validation
= False
20 def handle(self
, *fixture_labels
, **options
):
21 from django
.core
.management
import call_command
22 from django
.db
import connection
24 verbosity
= int(options
.get('verbosity'))
25 interactive
= options
.get('interactive')
26 addrport
= options
.get('addrport')
28 # Create a test database.
29 db_name
= connection
.creation
.create_test_db(verbosity
=verbosity
, autoclobber
=not interactive
)
31 # Import the fixture data into the test database.
32 call_command('loaddata', *fixture_labels
, **{'verbosity': verbosity
})
34 # Run the development server. Turn off auto-reloading because it causes
35 # a strange error -- it causes this handle() method to be called
37 shutdown_message
= '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name
38 use_threading
= connection
.features
.test_db_allows_multiple_connections
39 call_command('runserver',
41 shutdown_message
=shutdown_message
,
43 use_ipv6
=options
['use_ipv6'],
44 use_threading
=use_threading