# Starting polls again

**URL:** <https://forum.djangoproject.com/t/starting-polls-again/3292>\
**Category:** Using Django\
**Created:** [July 6, 2020, 12:20am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292 "2020-07-06T00:20:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 6, 2020, 12:20am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/1 "2020-07-06T00:20:29Z")

</div>

I am starting the polls project for the second time. I decided this time to go through the beginning instructions religiously. I work my way down to “python manage.py run server” which should work fine, but I get "No module named “able2.settings”. Of course, right there it is in the file structure — able2/able2/settings.py.

able2 is the name I gave the project in PyCharm. So, the project actually looks like this: Able2/able2/able2/settings.py

what gives?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 6, 2020, 12:41am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/2 "2020-07-06T00:41:21Z")

</div>

Best guess is that you’re in the wrong directory when trying to run this.

For “able2.settings” to be a valid reference, you’d need to be in Able2/able2 as your current directory.

What directory is your manage.py in?

(Also, and I’m guessing it’s a typing error when composting your message, but it’s `python manage.py runserver` - runserver as 1 word, not “run server” as 2 words.)

Ken

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 6, 2020, 1:21am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/3 "2020-07-06T01:21:44Z")

</div>

Yes on the typo, but Able2/able2/able2

There I have **init**.py. asgi.py. settings.py urls.py. wsgi.py. which probably all should be up a level.

I think I have an extra able2 folder somehow

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 6, 2020, 1:27am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/4 "2020-07-06T01:27:04Z")

</div>

Now I get an error that Django is not installed, which of course it is. I am throwing everything away and starting over. I did this just fine the first time.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 6, 2020, 1:54am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/5 "2020-07-06T01:54:42Z")

</div>

No, those are the right directory for those files.

Which means your current directory for running the manage.py command should be one level up, Able2/able2

Python considers directories to be [modules](https://docs.python.org/3.7/tutorial/modules.html#modules). (A bit of a simplification, but close enough for discussion purposes for now.)

So if your current directory is Able2/able2, then a reference to the module able2/settings would be a file in Able2/able2/able2/settings.py.

Having the extra directory isn’t a problem as long as your current directory is the right directory for your file structure.

Ken

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 6, 2020, 3:46pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/6 "2020-07-06T15:46:13Z")

</div>

Wow. So, I put everything at the right level and Django disappeared.  
Starting over once again. I could not find a way to resolve the issue  
of “no polls.detail” when it is right there in plain sight. So, I am  
going to try to work all the way down to it again and see if it is still  
a problem. It simply doesn’t make any sense.

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 14, 2020, 7:47pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/7 "2020-07-14T19:47:48Z")

</div>

Plus, I got through the “NoReverse…” stuff and how have " TemplateDoesNotExist for a template name “polls/question\_detail.html” which definitely DOES NOT exist. I have looked through my code to find where the program came up with this address and can’t find. It is the result of clicking on one of the questions that appear in the questions list. It has to be in the code somewhere doesn’t it. I am going to try a search in PyCharm on “question\_detail”

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 14, 2020, 8:07pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/8 "2020-07-14T20:07:37Z")

</div>

That would be an indication of something going wrong in the latter steps of part 4.  
See [Amend views](https://docs.djangoproject.com/en/3.0/intro/tutorial04/#amend-views) and the text below the example where it explains about question\_detail being the default template being looked for if you don’t have the generic view defined correctly.

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 14, 2020, 11:14pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/9 "2020-07-14T23:14:55Z")

</div>

OK. Well, if followed you lead and after awhile I found the problem.  
It was great except now there is another problem. Oh, that’s how it  
works, right?

Thank you Ken.

Ralph

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 17, 2020, 9:47pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/10 "2020-07-17T21:47:54Z")

</div>

This is driving me crazy. There is something fundamentally wrong with what I am doing. I am going back into projects in PyCharm and trying to run them. I can’t even get to the index page with getting a 404 telling me its tried the URL patterns, say polls/ or admin/ and the empty path doesn’t match any these. This is projects that were working. Now I am going back into them looking for hints and I get this all the time. I always check the pwd and it is correct. I just don’t understand what has happened.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 18, 2020, 12:12am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/11 "2020-07-18T00:12:04Z")

</div>

Sounds more like a Python environmental issue rather than a Django configuration issue. I’d look at how your packages are installed and see how things work directly from the command line rather than through PyCharm to see what might be going wrong that may be masked by PyCharm.

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [July 18, 2020, 12:35am UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/12 "2020-07-18T00:35:29Z")

</div>

Hi Ken,  
I think you are right on. I had to stop for the day I was just so  
frustrated. But, of course, I couldn’t stop thinking about and I  
started wondering about PyCharm. I am pretty sure that I haven’t had  
these problems when I have started everything from the command line in  
Terminal. I will try that tomorrow. Plus, maybe I am not using PyCharm  
correctly.

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [August 26, 2020, 5:06pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/13 "2020-08-26T17:06:22Z")

</div>

Are you still around? If so, could you look at this?

Looking at my post it seems that there is not much to go on in terms of understanding my problem. So, let me try to provide more detail.

I am in part 2 of the tutorial working with “models” (sqlite) and have written this code into "polls/models.py:

```auto
from django.db import models
from django.utils import timezone
import datetime

# Create your models here.

class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date_published')
def __str__ (self):

return self.question_text

def was_published_recently(self):

return self.pub_date >= timezone.now()

datetime.timedelta(days=1)

class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__ (self):

return self.choice_text

```

The indents are correct, just not shown in the markdown.

This is the shell command that brought the error:

Question.objects.get(pub\_date\_year=current\_year)

Something is wrong with defining “current\_year” and making it work. Can anyone see the problem?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 26, 2020, 5:17pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/14 "2020-08-26T17:17:43Z")

</div>

Including the full and complete statement being entered along with the error message may help.

You’re trying to reference a field named `pub_date_year` - no such field exists. What you’re really trying to get to is the year component within the pub\_date object, which is referenced with the _double underscore_, which means you want `pub_date__year`.

Ken

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [August 26, 2020, 6:09pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/15 "2020-08-26T18:09:15Z")

</div>

Thanks, but not sure what the “full and complete statement” means. The shell command is Question.objects.get(pub\_date\_year). I thought that this code would set up the the pub\_date object access:

```auto
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date_published')
    def __str__ (self):

        return self.question_text

    def was_published_recently(self):

        return self.pub_date >= timezone.now()

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 26, 2020, 6:18pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/16 "2020-08-26T18:18:45Z")

</div>

> [@reb](#):
>
> Thanks, but not sure what the “full and complete statement” means. The shell command is Question.objects.get(pub\_date\_year).

I am referring to what you were entering in the shell, followed by the error message you received as a response.

The statement `Question.objects.get(pub_date_year)` isn’t valid syntactically, and doesn’t match any of the examples in the docs. So I’m just trying to establish what it is you’re trying to do, and then use that information to try and explain why you’re getting the error message you’re receiving.

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [August 26, 2020, 6:44pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/17 "2020-08-26T18:44:16Z")

</div>

If you print out the tutorial, which is the only way I can reference the reference, on page 8, about ½ way down is:  
“\>\>\> Question.objects.get(pub\_date\_year=current\_date)”

Sorry, I truncated it in the “help” message, but that command produces the error:  
FieldError: Cannot resolve keyword ‘pub\_date\_year’ into field. Choices are: choice, id, pub\_date, question\_text

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [August 26, 2020, 6:51pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/18 "2020-08-26T18:51:00Z")

</div>

Here is how the code looks on the tutorial page

```auto
def was_published_recently(self):
    return self.pub_date >+ timezone.now() - datetime.timedelta(days=1)

```

That formatting, which I don’t understand, produces a coding error, so I erased the dash and move the line datetime.timedelta(days=1) down two lines and left justified it.

I didn’t include that in the code snippet above. But, it’s two lines down and in line with “Class” above. That was the only way I could get the interpreter to accept it.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 26, 2020, 6:57pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/19 "2020-08-26T18:57:06Z")

</div>

You’re trying to reference a field named `pub_date_year` - no such field exists. What you’re really trying to get to is the year component within the pub\_date object, which is referenced with the _double underscore_ , which means you want `pub_date__year` .

---

<div class="post-metadata">

**Author:** ![reb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/reb/32/1434_2.png) [@reb](https://forum.djangoproject.com/u/reb)\
**Post date:** [August 26, 2020, 7:02pm UTC](https://forum.djangoproject.com/t/starting-polls-again/3292/21 "2020-08-26T19:02:58Z")

</div>

Look at this! It worked.

### 

[maxim.z...@gmail.com](mailto:maxim.z...@gmail.com)

unread,

Aug 25, 2020, 3:11:20 PM (yesterday)







to [django...@googlegroups.com](mailto:django...@googlegroups.com)

Hi, use double underscore before startswith and year:

In [9]: Question.objects.filter(question\_text **\_\_**  **startswith** =‘What’)

In [12]: Question.objects.get(pub\_date **\_\_**  **year** =current\_year)

Now, that is not in the tutorial. How am I supposed to know that? How is any reader/student supposed to know that? Seems a bit frustrating.

Thanks to:  
Best regards, Maxim Zemlyakov Email: [maxim.z...@gmail.com](mailto:maxim.z...@gmail.com) GSM: +79032703210

[Next page](https://forum.djangoproject.com/t/starting-polls-again/3292.md?page=2)
