10 examples of 'django admin startproject' in Python

Every line of 'django admin startproject' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
12def start_project():
13 """
14 Copy a project template, replacing boilerplate variables.
15
16 """
17 usage = "usage: %prog [options] project_name [base_destination_dir]"
18 parser = optparse.OptionParser(usage=usage)
19 parser.add_option('-t', '--template-dir', dest='src_dir',
20 help='project template directory to use',
21 default=TEMPLATE_DIR)
22 options, args = parser.parse_args()
23 if len(args) not in (1, 2):
24 parser.print_help()
25 sys.exit(1)
26 project_name = args[0]
27
28 src = options.src_dir
29 if len(args) > 1:
30 base_dest_dir = args[1]
31 else:
32 base_dest_dir = ''
33 dest = os.path.join(base_dest_dir, project_name)
34
35 # Get any boilerplate replacement variables:
36 replace = {}
37 for var, help, default in utils.get_boilerplate(src, project_name):
38 help = help or var
39 if default is not None:
40 prompt = '%s [%s]: ' % (help, default)
41 else:
42 prompt = '%s: ' % help
43 value = None
44 while not value:
45 value = raw_input(prompt) or default
46 replace[var] = value
47
48 # Put in the rest of the replacement variables
49 REPO_PATH = os.path.join(os.getcwd(), replace['myproject'])
50 replace.update({
51 '$REPO_PATH': REPO_PATH,
52 '$PROJECT_NAME': replace['myproject'],
53 '$PROJECT_PATH': os.path.join(REPO_PATH, replace['myproject']),
54 '_gitignore': '.gitignore',
55 })
56 utils.copy_template(src, dest, replace)
57 subprocess.call(['python', os.path.join(dest, 'bin/bootstrap.py'), 'dev'])
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

28def handle(self, **options):
29 xmlreporting = options.get('xml_reporting', False)
30 test_all = options.get('test_all', False)
31
32 if xmlreporting:
33 settings.TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.run_tests'
34 settings.TEST_OUTPUT_VERBOSE = True
35 settings.TEST_OUTPUT_DESCRIPTIONS = True
36 settings.TEST_OUTPUT_DIR = 'xmlrunner'
37
38 if test_all:
39 call_command('test')
40 else:
41 args = ['test'] + settings.DEV_APPS
42 print(args)
43
44 call_command(*args)
9def run_in_demo_projects(ctx, admin_cmd, *more, **kwargs):
10 """Run the given shell command in each demo project (see
11 :attr:`ctx.demo_projects`).
12
13 """
14 cov = kwargs.pop('cov', False)
15 for mod in ctx.demo_projects:
16 # print("-" * 80)
17 # print("In demo project {0}:".format(mod))
18 m = import_module(mod)
19 # 20160710 p = m.SITE.cache_dir or m.SITE.project_dir
20 p = m.SITE.project_dir
21 with cd(p):
22 # m = import_module(mod)
23 if cov:
24 args = ["coverage"]
25 args += ["run --append"]
26 args += ["`which django-admin.py`"]
27 datacovfile = ctx.root_dir.child('.coverage')
28 if not datacovfile.exists():
29 print('No .coverage file in {0}'.format(ctx.project_name))
30 os.environ['COVERAGE_FILE'] = datacovfile
31 else:
32 args = ["django-admin.py"]
33 args += [admin_cmd]
34 args += more
35 args += ["--settings=" + mod]
36 cmd = " ".join(args)
37 print("-" * 80)
38 print("Run in demo project {0}\n$ {1} :".format(p, cmd))
39 ctx.run(cmd, pty=True)
11def do_run(self, *args):
12 builder = ProjectBuilder(*args)
13 builder.build()
73@task
74def start(ctx, project_name='radioco'):
75 ctx.run('rhc app start -a {}'.format(project_name))
16def handle(self, **options):
17 project_name, target = options.pop('name'), options.pop('directory')
18 self.validate_name(project_name, "project")
19
20 # Check that the project_name cannot be imported.
21 try:
22 import_module(project_name)
23 except ImportError:
24 pass
25 else:
26 raise CommandError(
27 "%r conflicts with the name of an existing Python module and "
28 "cannot be used as a project name. Please try another name." % project_name
29 )
30
31 # Create a random SECRET_KEY to put it in the main settings.
32 options['secret_key'] = get_random_secret_key()
33
34 super(Command, self).handle('project', project_name, target, **options)
21def run(self):
22 import django
23 from django.conf import settings
24 from django.core.management import call_command
25
26 settings.configure(
27 DATABASES={
28 'default': {
29 'NAME': ':memory:',
30 'ENGINE': 'django.db.backends.sqlite3',
31 }
32 },
33 INSTALLED_APPS=(
34 'django.contrib.auth',
35 'django.contrib.contenttypes',
36 'conditions',
37 'conditions.tests',
38 ),
39 MIDDLEWARE_CLASSES=()
40 )
41 django.setup()
42 call_command('migrate')
43 call_command('test')
28@pytest.mark.slowtest
29def test_actually_creates_django_project_in_virtualenv_with_hacked_settings_and_static_files(
30 self, fake_home, virtualenvs_folder, api_token
31):
32 running_python_version = ".".join(python_version().split(".")[:2])
33 with patch("scripts.pa_start_django_webapp_with_virtualenv.DjangoProject.update_wsgi_file"):
34 with patch("pythonanywhere.api.webapp.call_api"):
35 main("mydomain.com", "2.2.12", running_python_version, nuke=False)
36
37 django_version = (
38 subprocess.check_output(
39 [
40 str(virtualenvs_folder / "mydomain.com/bin/python"),
41 "-c" "import django; print(django.get_version())",
42 ]
43 )
44 .decode()
45 .strip()
46 )
47 assert django_version == "2.2.12"
48
49 with (fake_home / "mydomain.com/mysite/settings.py").open() as f:
50 lines = f.read().split("\n")
51 assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
52 assert "ALLOWED_HOSTS = ['mydomain.com']" in lines
53
54 assert "base.css" in os.listdir(str(fake_home / "mydomain.com/static/admin/css"))
388def setup(*args, **kwargs):
389 """
390 Call with the names of the enviroments to setup and optionally add the mirror keyword argument.
391 fab -H user@host setup:production,staging,development,mirror=y
392 """
393
394 mirror = kwargs.get('mirror','n')
395 setup_server(mirror)
396 setup_django(*args, **kwargs)
397 put_config_files(*args)
9def main() -> None:
10 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
11 execute_from_command_line(sys.argv)

Related snippets