Changeset 261
- Timestamp:
- 07/20/05 21:17:45 (3 years ago)
- Files:
-
- django/trunk/django/bin/django-admin.py (modified) (2 diffs)
- django/trunk/django/core/management.py (modified) (1 diff)
- django/trunk/docs/tutorial02.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/bin/django-admin.py
r252 r261 6 6 ACTION_MAPPING = { 7 7 'adminindex': management.get_admin_index, 8 'createsuperuser': management.createsuperuser, 8 9 # 'dbcheck': management.database_check, 9 10 'runserver': management.runserver, … … 64 65 if not ACTION_MAPPING.has_key(action): 65 66 print_error("Your action, %r, was invalid." % action, sys.argv[0]) 66 if action == 'init':67 if action in ('createsuperuser', 'init'): 67 68 ACTION_MAPPING[action]() 68 69 elif action in ('startapp', 'startproject'): django/trunk/django/core/management.py
r256 r261 374 374 startapp.args = "[appname]" 375 375 376 def createsuperuser(): 377 "Creates a superuser account." 378 from django.core import validators 379 from django.models.auth import users 380 import getpass 381 try: 382 while 1: 383 username = raw_input('Username (only letters, digits and underscores): ') 384 if not username.isalnum(): 385 sys.stderr.write("Error: That username is invalid.\n") 386 continue 387 try: 388 users.get_object(username__exact=username) 389 except users.UserDoesNotExist: 390 break 391 else: 392 sys.stderr.write("Error: That username is already taken.\n") 393 while 1: 394 email = raw_input('E-mail address: ') 395 try: 396 validators.isValidEmail(email, None) 397 except validators.ValidationError: 398 sys.stderr.write("Error: That e-mail address is invalid.\n") 399 else: 400 break 401 while 1: 402 password = getpass.getpass() 403 password2 = getpass.getpass('Password (again): ') 404 if password == password2: 405 break 406 sys.stderr.write("Error: Your passwords didn't match.\n") 407 except KeyboardInterrupt: 408 sys.stderr.write("\nOperation cancelled.\n") 409 sys.exit(1) 410 u = users.create_user(username, email, password) 411 u.is_staff = True 412 u.is_active = True 413 u.is_superuser = True 414 u.save() 415 print "User created successfully." 416 createsuperuser.args = '' 417 376 418 def runserver(port): 377 419 "Starts a lightweight Web server for development." django/trunk/docs/tutorial02.txt
r250 r261 11 11 12 12 .. admonition:: Philosophy 13 13 14 14 Generating admin sites for your staff or clients to add, change and delete 15 15 content is tedious work that doesn't require much creativity. For that reason, 16 16 Django entirely automates creation of admin interfaces for models. 17 17 18 18 Django was written in a newsroom environment, with a very clear separation 19 19 between "content publishers" and the "public" site. Site managers use the … … 21 21 displayed on the public site. Django solves the problem of creating a unified 22 22 interface for site administrators to edit content. 23 23 24 24 The admin isn't necessarily intended to be used by site visitors; it's for site 25 25 managers. 26 27 Create a user account 28 ===================== 29 30 Run the following command to create a superuser account for your admin site:: 31 32 django-admin.py createsuperuser --settings="myproject.settings.main" 33 34 (Note: You can use either "myproject.settings.main" or "myproject.settings.admin" 35 here. They both reference the same database.) 36 37 The script will prompt you for a username, e-mail address and password (twice). 26 38 27 39 Start the development server … … 49 61 .. image:: http://media.djangoproject.com/img/doc/tutorial/admin01.png 50 62 :alt: Django admin login screen 51 52 Create a user account53 =====================54 55 You can't log in, though, because you haven't created an admin user account56 yet. Drop into the Python interactive interpreter and type this::57 58 # The function django.models.auth.users.create_user() creates a new user59 # and returns the new auth.User object.60 # Don't use 'username' and 'password'. Those are just examples.61 >>> from django.models.auth import users62 >>> u = users.create_user('username', 'your_email@domain.com', 'password')63 64 # But we're not done. We need to explicitly set is_staff and is_active to65 # allow this user to access the admin. Might as well make it a superuser,66 # too.67 u.is_staff = True68 u.is_active = True69 u.is_superuser = True70 71 # Remember, call the save() method to save changes.72 u.save()73 63 74 64 Enter the admin site
