Problems with PyCharm Django example

Hi,

I'm new to PyCHarm/Django and may be asking a simple question, but I'm having trouble getting the Django example (on polls) to work.

I have the latest versions of both PyCharm and Django.

The first problem is that when I follow the instructions to create a Django Project, my directory structure differs from the one shown in the example.

The example (http://goo.gl/V9LrO) has this structure.

MyDjangoAPp

     MyDjangoApp

          polls

               __init__.py

               admin.py

               models.py

               tests.py

               views.py

          __init__.py

          manage.py

          my.py

          settings.py

          urls.py

     templates

I get

MyDjangoApp

     MyDjangoApp

          __init__.py

          settings.py

          urls.py

          wsgl.py

     polls

          __init__.py

          admin.py

          models.py

          tests.py

          views.py

      templates

      __init__.py

     manage.py

     my.py

     settings.py

     urls.py

As you can see, there are two settings.py files and two urls.py. files.  Why is that, and which one should I use?

In fact, I tried both of them. It seems that the one nested under MyDjangoApp/MyDjangoApp is the one to use. I say that because of a second problem.

I have no problem validating the models or running the server (with runserver), but when I actually run the project I get an error page. Instead of the administrative interface (http://goo.gl/TILgT) I get the following page.

It worked!

Congratulations on your first Django-powered page.

Of course, you haven't actually done any work yet. Here's what to do next:

  • If you plan to use a database, edit the DATABASES setting in MyDjangoProject/settings.py.
  • Start your first app by running python manage.py startapp [appname].

You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!

When I set the DEBUG to False in the second settings.py file, I still get that page. When I set DEBUG to False in the first settngs.py page I get a simpler error page: "A server error occurred.  Please contact the administrator."

So it seems that the first settings.py page is the relevant one. But why can't I reach the database? I have edited the settings.py file file as instructed.

# Django settings for MyDjangoProject project.

DEBUG = False

TEMPLATE_DEBUG = DEBUG

ADMINS = (

    # ('Your Name', 'your_email@example.com'),

)

MANAGERS = ADMINS

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

        'NAME': 'MyDatabase',                      # Or path to database file if using sqlite3.

        'USER': '',                      # Not used with sqlite3.

        'PASSWORD': '',                  # Not used with sqlite3.

        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.

        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

    }

}

But The system can't find the database.
Any help would be appreciated.
Thanks.
2 comments
Comment actions Permalink

I tried the same thing on a different computer and ran into a different problem.

This time the directory structure was again not the same as in the tutorial. It was the same as in my first message but without the extra files at the bottom.

MyDjangoApp

     MyDjangoApp

          __init__.py

          settings.py

          urls.py

          wsgl.py

     polls

          __init__.py

          admin.py

          models.py

          tests.py

          views.py

     templates

     manage.py

     MyDatabase

The error is that when I run it I get a yellow error screen with the following.

Exception Value:
No module named polls.models
Exception Location: C:\Users\facuser\PycharmProjects\MyDjangoApp\polls\admin.py in <module>, line 3

It's true that line 3 of admin.py refers to polls.models. (from MyDjangoApp.polls.models import Poll, Choice)

But the file MyDjangoApp\polls\models.py is in place. Why is it not seen as a module?

Thanks.

0
Comment actions Permalink

I found the answer. I started to run through the Django version of the same app. It explained that the outer MyDjangoApp was meaningless and was just a container for the project. The project itself is polls and one refers to its elements as polls.<whatever> -- but not MyDjangoApp.polls.<whatever>  The admin line that imports from MyDjangoApp.polls.models should really just import from polls.models. When I made that change, the admin site appeared.

The Django site also explained that the directory structure changed in version 1.4, which explains why it did not match the structure in the PyCharm tutorial.

0

Please sign in to leave a comment.