2012-12-19 48 views
5

我對django和web開發頗爲陌生。從「明確的指導Django的」學習創建超級用戶時,我得到以下錯誤(OS mac10.8.2 & django1.4.3)無法在syncdb後創建超級用戶

Would you like to create one now? (yes/no): yes 
Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line 
    utility.execute() 
    File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 232, in execute 
    output = self.handle(*args, **options) 
    File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 371, in handle 
    return self.handle_noargs(**options) 
    File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 110, in handle_noargs 
    emit_post_sync_signal(created_models, verbosity, interactive, db) 
    File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal 
    interactive=interactive, db=db) 
    File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send 
    response = receiver(signal=self, sender=sender, **named) 
    File "/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py", line 73, in create_superuser 
    call_command("createsuperuser", interactive=True, database=db) 
    File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 150, in call_command 
    return klass.execute(*args, **defaults) 
    File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 232, in execute 
    output = self.handle(*args, **options) 
    File "/Library/Python/2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 70, in handle 
    default_username = get_default_username() 
    File "/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py", line 105, in get_default_username 
    default_username = get_system_username() 
    File "/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py", line 85, in get_system_username 
    return getpass.getuser().decode(locale.getdefaultlocale()[1]) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale 
    return _parse_localename(localename) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename 
    raise ValueError, 'unknown locale: %s' % localename 
ValueError: unknown locale: UTF-8 

從明確指導的Django我顯示的車型之一。

from django.db import models 
class Publisher(models.Model): 
    name = models.CharField(max_length=30) 
    address = models.CharField(max_length=50) 
    city = models.CharField(max_length=60) 
    state_province = models.CharField(max_length=30) 
    country = models.CharField(max_length=50) 
    website = models.URLField() 

    def __str__(self): 
     return self.name 

    class Meta: 
     ordering = ['name'] 

setting.py數據庫設置爲: -

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'books', 
     'USER': 'postgres', 
     'PASSWORD': '******', 
     'HOST': 'localhost', 
     'PORT': '5432', 
    } 
} 

執行syncdb運行:

Creating tables ... 
Creating table auth_permission 
Creating table auth_group_permissions 
Creating table auth_group 
Creating table auth_user_user_permissions 
Creating table auth_user_groups 
Creating table auth_user 
Creating table django_content_type 
Creating table django_session 
Creating table django_site 
Creating table books_publisher 
Creating table books_author 
Creating table books_book_authors 
Creating table books_book 
是後

創建超級用戶我得到的錯誤。

+0

可能重複 - http://stackoverflow.com/questions/10891255/adding-a-database-to-the-django- project-using-sqlite3-with-python-2-7 –

+0

是的,它是重複的,儘管之前有大量的搜索,但找不到它。感謝您指出。 – user1572215

+0

它通常是一個很好的開始將堆棧跟蹤的最後一行復制到谷歌(用引號將它包裹起來) –

回答

2

我認爲這是你需要的東西:http://patrick.arminio.info/blog/2012/02/fix-valueerror-unknown-locale-utf8/

DRTL:添加到您的~/.bash_profile文件這些行:

export LANG="en_US.UTF-8" 
export LC_COLLATE="en_US.UTF-8" 
export LC_CTYPE="en_US.UTF-8" 
export LC_MESSAGES="en_US.UTF-8" 
export LC_MONETARY="en_US.UTF-8" 
export LC_NUMERIC="en_US.UTF-8" 
export LC_TIME="en_US.UTF-8" 
export LC_ALL="en_US.UTF-8" 

這是OSX錯誤。你可以在這裏找到更多的細節:https://code.djangoproject.com/ticket/5846

+0

感謝您的快速答覆defuz。將檢查出來 – user1572215

2

看起來你沒有在你的系統上安裝正確的本地人。

試圖運行執行syncdb之前鍵入以下 -

export LC_CTYPE=en_US.UTF-8 
export LC_ALL=en_US.UTF-8 

(或任何當地的應該是)。

線或者添加到您的~/.bash_profile

看看this question

相關問題