Форум сайта python.su
В терминале Linux Mint 17.1 x64
$ python -V
Python 2.7.6
python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import django
>>> django.VERSION
File “<stdin>”, line 1
django.VERSION
^
IndentationError: unexpected indent
>>> print (django.get_version())
1.6.1
>>>
Дальше в Pycharm
""" Django settings for test1 project. For more information on this file, see https://docs.djangoproject.com/en/1.6/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'dld=0ww^y78(!_ujpxp_bz9rkb_=xzs80)wt+^ccxv(0yeszd)' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'Test1', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'test1.urls' WSGI_APPLICATION = 'test1.wsgi.application' # Database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD': '1', 'HOST': '', # Set to empty string for localhost. 'PORT': '', # Set to empty string for default. } } # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_URL = '/static/' TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), )
bash -cl "/usr/bin/python2.7 /opt/pycharm-4.0.5/helpers/pycharm/django_manage.py sql auth /home/andrey/PycharmProjects/test1" Traceback (most recent call last): File "/opt/pycharm-4.0.5/helpers/pycharm/django_manage.py", line 41, in <module> run_module(manage_file, None, '__main__', True) File "/usr/lib/python2.7/runpy.py", line 176, in run_module fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code mod_name, mod_fname, mod_loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/andrey/PycharmProjects/test1/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in handle app_output = self.handle_app(app, **options) File "/usr/lib/python2.7/dist-packages/django/core/management/commands/sql.py", line 21, in handle_app return '\n'.join(sql_create(app, self.style, connections[options.get('database')])) File "/usr/lib/python2.7/dist-packages/django/core/management/sql.py", line 30, in sql_create tables = connection.introspection.table_names() File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 1210, in table_names cursor = self.connection.cursor() File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 157, in cursor cursor = self.make_debug_cursor(self._cursor()) File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 129, in _cursor self.ensure_connection() File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 124, in ensure_connection self.connect() File "/usr/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 124, in ensure_connection self.connect() File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 112, in connect self.connection = self.get_new_connection(conn_params) File "/usr/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 116, in get_new_connection return Database.connect(**conn_params) File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect connection_factory=connection_factory, async=async) django.db.utils.OperationalError: ВАЖНО: пользователь "adm_petrov" не прошёл проверку подлинности (Peer) Proce
Офлайн
Предположу что вы через pgAdmin вы ходите через tcp-сокет, а джангой подключаетесь через unix-сокет и для них разные схемы аутентификации прописаны в pg_hba.conf(для unix-сокета peer, для tcp-скорее всего md5). Для проверки воткните ‘HOST’: ‘127.0.0.1’ - это должно заставить джангу ходить через tcp.
Отредактировано PooH (Июнь 28, 2015 14:30:39)
Офлайн
Вы верно предположили. Так сделал и заработало. Подскажите ещё, пожалуйста
Делаю по официальной документации Pycharm https://www.jetbrains.com/pycharm/quickstart/django_guide.html#BeforeStart
Остановился на Launching the admin site. Выдаёт ошибки
setting.py
""" Django settings for test1 project. For more information on this file, see https://docs.djangoproject.com/en/1.6/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'dld=0ww^y78(!_ujpxp_bz9rkb_=xzs80)wt+^ccxv(0yeszd)' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'Test1', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'test1.urls' WSGI_APPLICATION = 'test1.wsgi.application' # Database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD': '1', 'HOST': '127.0.0.1', # Set to empty string for localhost. 'PORT': '', # Set to empty string for default. } } # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_URL = '/static/' TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), )
from polls.models import Poll, Choice from django.contrib import admin class ChoiceInline(admin.TabularInline): model = Choice extra = 3 class PollAdmin(admin.ModelAdmin): fieldsets = [ (None, {'fields': ['question']}), ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}) ] inlines = [ChoiceInline] admin.site.register(Poll, PollAdmin)
from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField()
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'test1.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), )
Environment: Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.6.1 Python Version: 2.7.6 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'Test1') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware') Traceback: File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 99. resolver_match = resolver.resolve(request.path_info) File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve 337. for pattern in self.url_patterns: File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns 365. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module 360. self._urlconf_module = import_module(self.urlconf_name) File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module 40. __import__(name) File "/home/andrey/PycharmProjects/test1/test1/urls.py" in <module> 4. admin.autodiscover() File "/usr/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover 29. import_module('%s.admin' % app) File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module 40. __import__(name) File "/home/andrey/PycharmProjects/test1/Test1/admin.py" in <module> 1. from polls.models import Poll, Choice Exception Type: ImportError at / Exception Value: No module named polls.models
Отредактировано saikle (Июнь 28, 2015 16:05:49)
Офлайн
Если вы создали приложение Test1 то импортировать надо из Test1, а не из polls. Вообще лучше пройдите туториал на официальном сайте джанги. В джетбрайновском руководстве много опущено, подразумеваться, что вы знаете как работать с джангой, но не знаете как с ней работать в пайчарме.
Офлайн