diff -r c8000aad4c10 django/core/management/commands/runserver.py
a
|
b
|
|
15 | 15 | help='Allows serving static files even if DEBUG is True.'), |
16 | 16 | make_option('--adminmedia', dest='admin_media_path', default='', |
17 | 17 | help='Specifies the directory from which to serve admin media.'), |
| 18 | make_option('--addrport', action='store', dest='addrport', |
| 19 | type='string', default='', |
| 20 | help='port number or ipaddr:port to run the server on'), |
18 | 21 | ) |
19 | 22 | help = "Starts a lightweight Web server for development." |
20 | 23 | args = '[optional port number, or ipaddr:port]' |
… |
… |
|
22 | 25 | # Validation is called explicitly each time the server is reloaded. |
23 | 26 | requires_model_validation = False |
24 | 27 | |
25 | | def handle(self, addrport='', *args, **options): |
| 28 | def handle(self, *args, **options): |
26 | 29 | import django |
27 | 30 | from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException |
28 | 31 | from django.core.handlers.wsgi import WSGIHandler |
29 | 32 | from django.contrib.staticfiles.handlers import StaticFilesHandler |
30 | | if args: |
| 33 | # addrport can be passed either as either positional or keyword option. |
| 34 | # keyword supersedes positional |
| 35 | addrport = options.get('addrport') |
| 36 | if len(args) > 1: |
31 | 37 | raise CommandError('Usage is runserver %s' % self.args) |
32 | | if not addrport: |
33 | | addr = '' |
34 | | port = '8000' |
35 | | else: |
36 | | try: |
37 | | addr, port = addrport.split(':') |
38 | | except ValueError: |
39 | | addr, port = '', addrport |
| 38 | addrport = addrport or (args and args[0]) or '8000' |
| 39 | try: |
| 40 | addr, port = addrport.split(':') |
| 41 | except ValueError: |
| 42 | addr, port = '', addrport |
40 | 43 | if not addr: |
41 | 44 | addr = '127.0.0.1' |
42 | 45 | |
diff -r c8000aad4c10 django/core/management/commands/testserver.py
a
|
b
|
|
1 | 1 | from django.core.management.base import BaseCommand |
2 | 2 | |
3 | 3 | from optparse import make_option |
| 4 | import re |
4 | 5 | |
5 | 6 | class Command(BaseCommand): |
6 | 7 | option_list = BaseCommand.option_list + ( |
… |
… |
|
11 | 12 | help='port number or ipaddr:port to run the server on'), |
12 | 13 | ) |
13 | 14 | help = 'Runs a development server with data from the given fixture(s).' |
14 | | args = '[fixture ...]' |
| 15 | args = '[optional port number, or ipaddr:port] [fixture ...]' |
15 | 16 | |
16 | 17 | requires_model_validation = False |
17 | 18 | |
… |
… |
|
23 | 24 | interactive = options.get('interactive', True) |
24 | 25 | addrport = options.get('addrport') |
25 | 26 | |
| 27 | # if no --addrport option specified, check to see whether first element |
| 28 | # of fixture labels looks like [address:]port. If so, use it as an addrport |
| 29 | # spec. |
| 30 | if not addrport and len(fixture_labels) > 0: |
| 31 | r = re.compile('(.+:)?\d+$') |
| 32 | if r.match(fixture_labels[0]): |
| 33 | addrport = fixture_labels[0] |
| 34 | fixture_labels = fixture_labels[1:] |
| 35 | |
26 | 36 | # Create a test database. |
27 | 37 | db_name = connection.creation.create_test_db(verbosity=verbosity, autoclobber=not interactive) |
28 | 38 | |
diff -r c8000aad4c10 docs/man/django-admin.1
a
|
b
|
|
75 | 75 | .B runfcgi help |
76 | 76 | for help on the KEY=val pairs. |
77 | 77 | .TP |
78 | | .BI "runserver [" "\-\-noreload" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]" |
| 78 | .BI "runserver [" "\-\-noreload" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "\-\-addrport=port|ipaddr:port" "] [" "port|ipaddr:port" "]" |
79 | 79 | Starts a lightweight Web server for development. |
80 | 80 | .TP |
81 | 81 | .BI "shell [" "\-\-plain" "]" |
… |
… |
|
132 | 132 | Runs the test suite for the specified applications, or the entire project if |
133 | 133 | no apps are specified |
134 | 134 | .TP |
135 | | .BI "testserver [" "\-\-addrport=ipaddr|port" "] [" "fixture fixture ..." "]" |
| 135 | .BI "testserver [" "\-\-addrport=ipaddr|ipaddr:port" "] [" "ipaddr:port|port" "] [" "fixture fixture ..." "]" |
136 | 136 | Runs the test suite for the specified applications, or the entire project if |
137 | 137 | no apps are specified |
138 | 138 | .TP |
diff -r c8000aad4c10 docs/ref/django-admin.txt
a
|
b
|
|
716 | 716 | Port 8000 on IP address 1.2.3.4:: |
717 | 717 | |
718 | 718 | django-admin.py runserver 1.2.3.4:8000 |
| 719 | django-admin.py runserver --addrport=1.2.3.4:8000 |
719 | 720 | |
720 | 721 | Port 7000 on IP address 127.0.0.1:: |
721 | 722 | |
722 | 723 | django-admin.py runserver 7000 |
| 724 | django-admin.py runserver --addrport=7000 |
723 | 725 | |
724 | 726 | Port 7000 on IP address 1.2.3.4:: |
725 | 727 | |
726 | 728 | django-admin.py runserver 1.2.3.4:7000 |
| 729 | django-admin.py runserver --addrport=1.2.3.4:7000 |
727 | 730 | |
728 | 731 | Serving static files with the development server |
729 | 732 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
… |
… |
|
945 | 948 | Use the :djadminopt:`--failfast` option to stop running tests and report the failure |
946 | 949 | immediately after a test fails. |
947 | 950 | |
948 | | testserver <fixture fixture ...> |
| 951 | testserver [ipaddr:port|port] <fixture fixture ...> |
949 | 952 | -------------------------------- |
950 | 953 | |
951 | 954 | .. django-admin:: testserver |
… |
… |
|
991 | 994 | the default of 127.0.0.1:8000. This value follows exactly the same format and |
992 | 995 | serves exactly the same function as the argument to the ``runserver`` command. |
993 | 996 | |
| 997 | For consistency with the ``runserver`` command, you can also specify |
| 998 | the IP address and port before the list of fixtures. If testserver |
| 999 | finds something of the form ``ipaddress:port|port`` as the first item |
| 1000 | of the fixture list, it will take it to be an address specification. |
| 1001 | |
994 | 1002 | Examples: |
995 | 1003 | |
996 | 1004 | To run the test server on port 7000 with ``fixture1`` and ``fixture2``:: |
997 | 1005 | |
998 | 1006 | django-admin.py testserver --addrport 7000 fixture1 fixture2 |
| 1007 | django-admin.py testserver 7000 fixture1 fixture2 |
999 | 1008 | django-admin.py testserver fixture1 fixture2 --addrport 7000 |
1000 | 1009 | |
1001 | | (The above statements are equivalent. We include both of them to demonstrate |
1002 | | that it doesn't matter whether the options come before or after the fixture |
1003 | | arguments.) |
| 1010 | (The above statements are equivalent. We include all of them to |
| 1011 | demonstrate that it doesn't matter whether the options come before or |
| 1012 | after the fixture arguments when you use the keyword argument form for |
| 1013 | the address specification, but it does matter if you omit the keyword.) |
1004 | 1014 | |
1005 | 1015 | To run on 1.2.3.4:7000 with a ``test`` fixture:: |
1006 | 1016 | |
1007 | 1017 | django-admin.py testserver --addrport 1.2.3.4:7000 test |
| 1018 | django-admin.py testserver 1.2.3.4:7000 test |
1008 | 1019 | |
1009 | 1020 | .. versionadded:: 1.3 |
1010 | 1021 | |