Ticket #7000: open_browser.1.diff

File open_browser.1.diff, 4.1 KB (added by jezdez, 7 years ago)

patch including docs

  • django/core/management/commands/runserver.py

     
    77    option_list = BaseCommand.option_list + (
    88        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
    99            help='Tells Django to NOT use the auto-reloader.'),
     10        make_option('--browser', action='store_true', dest='open_browser',
     11            help='Tells Django to open a browser.'),
    1012        make_option('--adminmedia', dest='admin_media_path', default='',
    1113            help='Specifies the directory from which to serve admin media.'),
    1214    )
     
    3739            raise CommandError("%r is not a valid port number." % port)
    3840
    3941        use_reloader = options.get('use_reloader', True)
     42        open_browser = options.get('open_browser', False)
    4043        admin_media_path = options.get('admin_media_path', '')
    4144        shutdown_message = options.get('shutdown_message', '')
    4245        quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
     
    5154            try:
    5255                path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
    5356                handler = AdminMediaHandler(WSGIHandler(), path)
     57                if open_browser:
     58                    import webbrowser
     59                    url = "http://%s:%d/" % (addr, port)
     60                    webbrowser.open(url)
    5461                run(addr, int(port), handler)
    5562            except WSGIServerException, e:
    5663                # Use helpful error messages instead of ugly tracebacks.
     
    7077                if shutdown_message:
    7178                    print shutdown_message
    7279                sys.exit(0)
    73         if use_reloader:
     80        if use_reloader and not open_browser:
    7481            from django.utils import autoreload
    7582            autoreload.main(inner_run)
    7683        else:
  • extras/django_bash_completion

     
    4242    prev="${COMP_WORDS[COMP_CWORD-1]}"
    4343
    4444    # Standalone options
    45     opts="--help --settings --pythonpath --noinput --noreload --format --indent --verbosity --adminmedia --version"
     45    opts="--help --settings --pythonpath --noinput --noreload --browser --format --indent --verbosity --adminmedia --version"
    4646    # Actions
    4747    actions="adminindex createcachetable dbshell diffsettings \
    4848             dumpdata flush inspectdb loaddata reset runfcgi runserver \
  • docs/man/django-admin.1

     
    5353.B runfcgi help
    5454for help on the KEY=val pairs.
    5555.TP
    56 .BI "runserver [" "\-\-noreload" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
     56.BI "runserver [" "\-\-noreload" "] [" "\-\-browser" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
    5757Starts a lightweight Web server for development.
    5858.TP
    5959.BI "shell [" "\-\-plain" "]"
     
    136136.TP
    137137.I \-\-adminmedia=ADMIN_MEDIA_PATH
    138138Specifies the directory from which to serve admin media when using the development server.
     139.TP
     140.I \-\-browser
     141Open the URL of the development server in the default web browser.
    139142
    140143.SH "ENVIRONMENT"
    141144.TP
  • docs/django-admin.txt

     
    389389
    390390    django-admin.py runserver --adminmedia=/tmp/new-admin-style/
    391391
     392--browser
     393~~~~~~~~~
     394
     395Use the ``--browser`` option to tell Django to open the URL of the development
     396server automatically with the system web browser. As soon as you start it with
     397this option the use of the auto-reloader is disabled to prevent a recurring
     398opening in the browser.
     399
     400Example usage::
     401
     402    django-admin.py runserver --browser
     403
    392404--noreload
    393405~~~~~~~~~~
    394406
Back to Top