Beginner needs help getting templates to work - is this the right group?

90 views
Skip to first unread message

Philip Means

unread,
Mar 5, 2020, 9:05:13 PM3/5/20
to Django users
I am new to web development.  Wanted to help my daughter with a simple website (she does pet portraits) and learn something that interests me.  I watched some you tube tutorials, then bought a book.  First couple simple projects went OK.  Then I got to templates and I have not been able to get the example project to work.  Been banging my head against the wall for about a week.  Part of the problem is my directory structure does not look like the authors and so I am not sure I am putting things in the right place. When I go searching for another explanation of how to set it up, I find that nobody seems to do it the same way.  Also, I find the jargon confusing.  At this point I just want to display a simple html page.  If this is in the wrong place, maybe someone can direct me to a better one.

Jorge Gimeno

unread,
Mar 5, 2020, 9:28:01 PM3/5/20
to django...@googlegroups.com
On Thu, Mar 5, 2020 at 6:04 PM Philip Means <mean...@gmail.com> wrote:
I am new to web development.  Wanted to help my daughter with a simple website (she does pet portraits) and learn something that interests me.  I watched some you tube tutorials, then bought a book.  First couple simple projects went OK.  Then I got to templates and I have not been able to get the example project to work.  Been banging my head against the wall for about a week.  Part of the problem is my directory structure does not look like the authors and so I am not sure I am putting things in the right place. When I go searching for another explanation of how to set it up, I find that nobody seems to do it the same way.  Also, I find the jargon confusing.  At this point I just want to display a simple html page.  If this is in the wrong place, maybe someone can direct me to a better one.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fe83a557-759d-460d-96ec-2c7fd18117bb%40googlegroups.com.

Django is a framework that supports a lot of features, and that means there's a lot of moving parts.  However, similar to driving a car, you need to know a few things to get things working, rather than knowing the niceties of how everything works.

To address your point about project structure, there's a lot of opinions on this (most of them are subjective). I have a structure I use and I'm comfortable with, but Django will support some variety in this.

Without seeing what code you have and what happens that is not expected, we don't know where we can help.  So, to help us understand, we need to know a few things.

1.  What steps did you take to get here?

2..  What goes wrong?  If there's a traceback, copying and pasting it is invaluable.

3.  We may ask to see code.  Again, copying and pasting that will help us understand what is going on.

You said that your project isn't working once you get to templates.  Is there a book or tutorial you are following?  That might help us know where to start.

In addition to this list, there is a forum at forum.djangoproject.com (I follow posts in there as well).  That might be another resource for you, as sometimes the question you have has already been answered.

-Jorge

Philip Means

unread,
Mar 5, 2020, 10:33:33 PM3/5/20
to django...@googlegroups.com
Thank you for your response.  The book is Django for Beginners, by William S. Vincent.  I will copy and send you the chapter I am having trouble with.  My directory structure, as created by Django, doesn't seem to be the same as his, so I will send you that as well.  The problem I am having
is that after the changes to the files have been made, and I "runserver" (on page 55) I get a huge error dialog that seems to say that django can't find the app. I have deleted the project several times and re-entered it, so I think it is unlikely that it is a typing error.  


Directory tree.pdf
Error dialog.pdf
Chapter 3 up to error.pdf

Shishir Jha

unread,
Mar 5, 2020, 11:02:12 PM3/5/20
to Django users
Can you show the code that you have written upto page 55?

Shishir Jha

unread,
Mar 5, 2020, 11:02:26 PM3/5/20
to django...@googlegroups.com
Can you show the code that you have written until page 55?


Jorge Gimeno

unread,
Mar 6, 2020, 1:04:41 AM3/6/20
to django...@googlegroups.com
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BC7wFQhMzBAWQH-f3N8uxcUYyPtPY8tLLn2Df0eL114DL9%3DQA%40mail.gmail.com.

One of the things about working with Django is that since it does so much for you behind the scenes, tracebacks can seem long and complicated.  Fortunately, there's two clues to what's going on.

These are two exceptions.  The first is a ModuleNotFoundError, which tells us that a module named 'pages.urls' could not be found.  The second error is an OSError, which happens on Windows since the Python exception raises an exception in Windows that the file could not be found.

I looked in the traceback and I found this line in the first exception's traceback: 

C:\Users\Phil\desktop\django\pages\pages_project\urls.py", line 21, in <module

path(", include('pages.urls')), #new

This shows the line where the exception occurred. When the server was attempting to load the urlpatterns, it couldn't find this module. The module is there, so I would check the INSTALLED_APPS variable in settings.py and check to see that 'pages.apps.PagesConfig', is in there. Let us know if this helps!

-Jorge

SHANKAR JHA

unread,
Mar 6, 2020, 6:07:26 AM3/6/20
to django...@googlegroups.com
Why don't you compare your code with the Github repo provided by the author: https://github.com/wsvincent/djangoforbeginners.

You can share your code with us for more clarity.

Byiringiro Yves

unread,
Mar 6, 2020, 6:07:26 AM3/6/20
to django...@googlegroups.com
Hello guys, I need your help!
How can I give a staff user a permission to create a user account in django?

Alvaro Orozco

unread,
Mar 6, 2020, 6:07:27 AM3/6/20
to django...@googlegroups.com
It seems like you're not activating the virtual environment. Active the virtual environment and install the dependencies.

Philip Means

unread,
Mar 6, 2020, 12:37:17 PM3/6/20
to django...@googlegroups.com

Thank you all for your help and your interest.  I am not sure how best to handle getting

Information that you all have requested.  Don’t want to clutter up the thread more than

necessary, so I will send the information to all that have shown interest as .pdf attachments in emails.

 

 

To Jorge Gimeno:  I checked the settings.py as you suggested to see if

'pages.apps.PagesConfig'  was correctly added and it appears OK

 

I also checked pages/urls.py and pages_project urls.py and they also appear correct.

 

Alvaro Orozco suggested that I might not have the virtual environment activated.  I think that was a possibility, so I did a “pipenv shell” and then “runserver” and the traceback appears to have changed a little.  I will email the new traceback to all who responded.

 

One thing that bothers me is that the author of the book refers to the pages directory as if there is only one.  In fact, django created two. The top level, (Is that referred to as the base?) has manage.py in it.  One of the childs of this is another ‘page’ which is where I put urls.py.  At one point I put urls.py

In both ‘page’ directories, figuring the one that the one in the wrong place would be ignored.  This didn’t seem to make any difference.  Is it possible that the book was written when there was only one “page” directory and the code in the book won’t work with a second “page” sub-directory?

 

To Shankar Jha:  Yes, I did compare my code with the Github code posted by the author and it matches perfectly, with one exception.  The exception is where a second template is added later in the chapter.  That is beyond where I encountered the error.

 

To Alvaro Orozco:  You are probably correct.  I may not have had the virtual environment active.  I have run it again and the traceback seems to have changed slightly. I will send you the new one by email.

 

To all:  I still have the problem and welcome your suggestions.


Jorge Gimeno

unread,
Mar 6, 2020, 5:35:16 PM3/6/20
to django...@googlegroups.com
I think Alvaro is on to something.  I just noticed that there ins't a virtual enviroment active, and the traceback shows that pipenv run wasn't used either. Can we try pipenv shell and then running python manage.py runserver again? If you didn't install Django using pipenv install, do that first.

-Jorge

Shishir Jha

unread,
Mar 6, 2020, 7:19:01 PM3/6/20
to django...@googlegroups.com

"One thing that bothers me is that the author of the book refers to the pages directory as if there is only one.  In fact, django created two. The top level, (Is that referred to as the base?) has manage.py in it.  One of the childs of this is another ‘page’ which is where I put urls.py.  At one point I put urls.py

In both ‘page’ directories, figuring the one that the one in the wrong place would be ignored.  This didn’t seem to make any difference.  Is it possible that the book was written when there was only one “page” directory and the code in the book won’t work with a second “page” sub-directory?"


Outer "pages" is just the directory to store the django project and initialise the project using pipenv and all. That has nothing to do with the project itself. The "pages" inside is one of the apps of the project(This project has only one app). Django has this concept of "projects" and "apps". Project means whole web application that you are developing and apps are specific functionalities inside the web app. So, pay attention to the "pages" folder inside only, it will have "urls.py" file to display pages in specific routes, and other "urls.py" is inside "pages_project" which represents whole project. The "urls.py" file here is to let django know which apps have urls setup and where to look for them


Ali Abubakar Muhd

unread,
Mar 6, 2020, 8:04:15 PM3/6/20
to django...@googlegroups.com
May  be you forgot to tell django where it looks for your template directory. To do this in your project directory go to setting and create a variable like this; 
TEMPLATE_DIR = os.path.join( BASE_DIR, 'templates')
Then locate TEMPLATES in your setting and put TEMPLATE_DIR variable in DIRS, like this 'DIRS':[TEMPLATE_DIR]. and by convension your template directory should be templates

On Friday, 6 March 2020, Philip Means <mean...@gmail.com> wrote:
I am new to web development.  Wanted to help my daughter with a simple website (she does pet portraits) and learn something that interests me.  I watched some you tube tutorials, then bought a book.  First couple simple projects went OK.  Then I got to templates and I have not been able to get the example project to work.  Been banging my head against the wall for about a week.  Part of the problem is my directory structure does not look like the authors and so I am not sure I am putting things in the right place. When I go searching for another explanation of how to set it up, I find that nobody seems to do it the same way.  Also, I find the jargon confusing.  At this point I just want to display a simple html page.  If this is in the wrong place, maybe someone can direct me to a better one.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

Vikash Chitransh

unread,
Mar 7, 2020, 9:31:12 AM3/7/20
to django...@googlegroups.com
I can help you in complete the book and create sample django application through skype.
With Regards,
Vikash Kumar

Deborah Emeni

unread,
Mar 7, 2020, 12:58:32 PM3/7/20
to django...@googlegroups.com
Hello Philip, I use the same tutorial book "Django for beginners" as you and I understand why the author of the book refers to the pages directory as if there is only one.
You are having two Directories because you ran this command:

 $ django-admin startproject pages

The Author of the book ran this other command below instead of yours, that is why it bothers you that the author refers to the pages directory as if there it were only one. See the command that makes this possible below:

$ django-admin startproject pages .

(the difference between the two commands is the space and dot after the name of your project, 'pages')

Reply all
Reply to author
Forward
0 new messages