PyCharm Django tutorial

Answered

I'm new to PyCharm and Django, was going through the tutorial, and found it frustrating because of the discrepancies from the current PyCharm product (2017.3.2 Professional Edition) and some of the steps were confusing.  Specifically:

  • After I create the proejct, there is no polls directory - is that as expected? 
  • I was unclear about the database and tried to just supply a simple name, leaving the engine alone (see the screenshot above).  I'm not sure if that's the right thing to do or not.

  • I think I was able to launch the Django server: I got a window for manage.py but I don't understand what I'm supposed to do at that point. 
    The tutorial states "enter task name in the manage.py console" but that makes no sense.  It is unclear to me from the screenshot what if anything was typed by the user.

I think the tutorial should match the current version of the product and should explain things for newbies who don't like myself who don't know what we're doing.  I'm going to try to play with Django natively without PyCharm.

4 comments
Comment actions Permalink

Hi Jpfuntne! I added a link to your post to the corresponding ticket in our bug tracker: PY-27950, the tutorial requires some changes indeed.

After I create the proejct, there is no polls directory

When creating new Django project in PyCharm there's an optional field for application, that's polls from the tutorial. Looks like you left it blank so no folder was created.

I was unclear about the database and tried to just supply a simple name

You can leave default settings for a database - it'll use sqlite3 which is a nice choice for playing around and doesn't require a specific configuration. 

I think I was able to launch the Django server: I got a window for manage.py

It's poorly written in fact, to start a server you can run runserver task in manage.py console, but that's an overcomplicated way, PyCharm creates a Run Configuration by default for running Django server:

If you have any additional questions please feel free to comment. By the way, let me suggest Django Girls tutorial: https://tutorial.djangogirls.org/en/ as a supplementary guide, it's probably the best Dajngo tutorial out there.

0
Comment actions Permalink

Thanks for your speedy reply, Pavel.  I'll see if I can make more progress with your tips and might be back for more. :)

0
Comment actions Permalink

I'm back continuing with PyCharm.  I created a new project with a polls application and got connected to the application after setting the database name.  Then I tried to add the Question model and got an error when I tried to open the manage.py console:

I searched around on the Internet and was able to change the model by supplying an "on_delete" parameter:

  question = models.ForeignKey(Question, on_delete=models.PROTECT)

I think the PyCharm help page could use this tip so that others won't encounter this problem.

0
Comment actions Permalink

Now I'm stuck while carrying out the Writing Views steps.  I have these files:

And when I try to run the app, I get:

================================================================================================

"C:\Program Files\JetBrains\PyCharm 2017.3.2\bin\runnerw.exe" C:\Users\jpfuntne\PycharmProjects\django1\venv\Scripts\python.exe C:/Users/jpfuntne/PycharmProjects/django1/manage.py runserver 10001
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001FE295E1D08>
Traceback (most recent call last):
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\core\management\base.py", line 364, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\core\management\base.py", line 351, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\core\checks\registry.py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\utils\functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\urls\resolvers.py", line 536, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\utils\functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\urls\resolvers.py", line 529, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\jpfuntne\PycharmProjects\django1\django1\urls.py", line 23, in <module>
url(r'^polls/', include('polls.url')),
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\jpfuntne\PycharmProjects\django1\venv\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'polls.url'

================================================================================================

Something doesn't seem right in the files.  django1\urls.py refers to polls.url - is that a filename?  The filename that the steps told me to create was polls\urls.py.  How do I fix this?  I thnk I can keep the name of the file as-is but need to refer to it as polls\urs.py or something like that.

0

Please sign in to leave a comment.