Automatically request a renewal of the default domain name when starting Djangos./manage.py syncdb?

Regarding the Django Sites module and manage.py syncdb

The Auth module can ask the superuser administrator by default at time. \ manage.py syncdb. I would like this to happen for the default domain name. This is currently example.com, hardcoded if I do not use the admin website to change it. I want to change it during syncdb.

+3
source share
2 answers

I made a small django application that can plug and play. To connect it:

  1. upload it to the project directory or where your project can find.
  2. settings.py INSTALLED_APPS, "site_default" ( ) "django.contrib.sites", .
  3. manage.py syncdb manage.py createdefaultsite

:

(pinax-dev)>manage.py createdefaultsite
Site domain name: mydomain.com
Site display name: My Site!
(pinax-dev)

unit test. unit test:

(pinax-dev)>manage.py test site_default

"site_default" - .

: http://github.com/peiwei/pinax/raw/master/pinax/apps/site_default.tgz

:

(pinax-dev)> manage.py syncdb
Creating table...
You just installed Django auth system, which means you don't have any superuse
rs defined.
Would you like to create one now? (yes/no): yes
Username: administrator
E-mail address: who@who.com
Password:
Password (again):
Superuser created successfully.

Would you like to change the default site domain name? (yes/no)[default:no]: yes

Site domain name: mydomain.com
Site display name: My Site!
...
Installing index for signup_codes.SignupCode model
Installing index for signup_codes.SignupCodeResult model
+6

:

  • post_syncdb

. , , sites. :

from django.contrib.sites import models as sites_app
signals.post_syncdb.connect(create_site, sender=sites_app)

create_site ( ) auth :

def create_site(app, created_models, verbosity, **kwargs):
from django.contrib.sites.models import Site
from django.core.management import call_command
if Site in created_models and kwargs.get('interactive', True):
    msg = "\nYou just installed Django sites system, which means you don't have " \
            "any sites defined.\nWould you like to create one now? (yes/no): "
    confirm = raw_input(msg)
    while 1:
        if confirm not in ('yes', 'no'):
            confirm = raw_input('Please enter either "yes" or "no": ')
            continue
        if confirm == 'yes':
            call_command("createsite", interactive=True)
        break

createsite, . , Django, example.com.

, . , -, , google django.

+4

Source: https://habr.com/ru/post/1734140/


All Articles