Django local library project - creating your home page - issues

learning

(Don Wagner) #1

Hello, I’m currently working through the Learn Web Development course and I have two questions. First I hope I’m in the right place and second this is a great course and I give kudos to those who developed the course. Both questions are in regard to the server-side website programming section -> django -> Part 5: creating our home page.

My first question is: I get a warning when I run the server. The warning is:

“WARNINGS:
?: (urls.W002) Your URL pattern ‘/’ has a route beginning with a ‘/’. Remove thi
s slash as it is unnecessary. If this pattern is targeted in an include(), ensur
e the include() pattern has a trailing ‘/’.

This warning is in reference to the /locallibrary/urls.py file, specifically this line of code:
urlpatterns += [
path(’/’, RedirectView.as_view(url=’/catalog/’, permanent=True)),
]

If I comment out this line the warning goes away. If I ignore the warning everything seems to still work anyway. Is there something wrong with the tutorial or is this normal?

My second question is: At the end of this section you are supposed to load the home page using http://127.0.0.1:8000 and you are supposed to be redirected to http://127.0.0.1:8000/catalog which shows the books library home page. This is not what actually happens. When I load http://127.0.0.1:8000 I get a 404 error. However if I append /catalog then I get the books library home page. So my question is: is the tutorial incorrect or is this the expected behavior?

I hope my questions are clear enough to understand and I appreciate any feedback. And if I’m asking this question in the wrong place then please just let me know and I’ll redirect to the correct place.

Thank you very much for your help.

don wagner


(Chris Mills) #2

Hi Don,

Thanks for getting in touch with us about this.

I’m afraid it is not the best time for you to be going through this — our server-side author (Hamish) is currently working through the Django/Python section and updating it all to make sure it uses the latest dependencies and errors such as this are fixed.

So for example, going forward the course requires Python 3. Are you using Python 3? It might be an idea to retrace your sets through the first few articles.

I am alerting @hamishwillee to this as well, so he can comment if needed.


(Don Wagner) #3

Chris, thank you so much for the quick response. Yes, I am using python 3, but curiously ‘py3 manage.py runserver’ doesn’t work, however, ‘python manage.py runserver’ does. Also, I have a friend who is working through this course with me and he is experiencing the same issues.

That said, and based on your email, I’m going to continue on with the course because I’m learning so much. Everything still works, it’s just that the tutorial seems a little off in the implementation. No big deal, it will make me a better programmer. I will also not hound you guys with questions since you mentioned Hamish is updating the course.

With all that said, I want you and your team to know how impressed I am with the Web Developer course. I have learned more than I ever expected. It’s professionally done and challenges me on many levels. I plan to spend a lot time here learning and eventually contributing.

Please tell Hamish that I’m available to help him in any way or to provide additional feedback if he so desires.

Go MDN!


(Hamish Willee) #4

Hi Don & Chris

Yes, I am working on this. The instructions “should work” now - ie build and run. However even though it builds, not everything has been updated to use the “recommended approach”. This is particularly true in the routes definition sections, where there has been a lot of change between Django 1.10 and 2.0. IN addition, the example on Github does not have all the latest matching code.

Looking at your questions:

  1. I don’t get the warning about the unnecessary slash in the route. It is though, and yes, you can ignore that. What platform are you using?
  2. Yes you are supposed to be redirected to home. I have tested that previously and will do so again. You can track that in https://github.com/mdn/django-locallibrary-tutorial/issues/8

I am using python 3, but curiously ‘py3 manage.py runserver’ doesn’t work, however, ‘python manage.py runserver’ does.

Where does it say use py3? It should say “py -3”.
The documentation explains in the dev environment section that you use py -3 on windows and python3 on Linux/macOS. You can use python IFF you only have python 3 installed - otherwise typically the system will run your code with python2.

I am glad you are enjoying the tutorial. Feel free to raise issues against the MDN project for any errors. You can also ask queries here, but please tag me or I may not see the them. I will be working on this over the next week, but then away for 2 weeks. Will leave it in a good state, though possibly not “complete”.

Cheers
Hamish


(Hamish Willee) #5

PS, though actually that “slash” warning appears in https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/skeleton_website (search for “Leave the first parameter of the path function empty”). Someone (else) added that section yesterday.

We get the same route error as you at the end of this topic. Should be fixed when you actually create the home page.


(Don Wagner) #6

Hi Hamish, sorry I was on a couple of days vacation.

YES !!!. That worked. I removed the first parameter and the warning is gone and http://127.0.0.1:8000 redirects to /catalog as expected. I brushed over that section too quickly and didn’t see it. Also, in my first post I miss-typed when I said “py3”. My apologies.

This course is amazing. I’ve learned so much and I can’t believe it’s free. Thank you very much.

don wagner


(Hamish Willee) #7

Great to hear you like it - we’re pretty proud of it too :-).

You should also check out the Django getting started tutorials. They aren’t quite as good for some sections (e.g. overview and Models) but go into more detail on some sections that I gloss over. I hope they are complementary!


(Don Wagner) #8

I will check those out. I believe you’re referring to the Django website for those tutorials?

Any possibility you will be developing any React tutorials?

Anyways, thanks again Hamish!


(Hamish Willee) #9

Yes, the Django website tutorials. I personally have no plans to develop a React tutorial. I’m not sure what the broader MDN has planned - @chrismills may know.


(Chris Mills) #10

Probably not. We chose Django and Express for the examples in this topic because they are established, popular, and widely used, and they show off classic server-side principles well. Now we’ve got examples in place, we don’t need (or want) to cover all framework possibilities, plus React blurs the lines a bit.

I might cover React a bit in a future planned modern JS tooling module…but that is a while off yet. No definite plans.


(Don Wagner) #11

@hamishwillee, just want to bring one quick thing to your attention. When I first created this project, the /catalog/urls.py was created with:

“from django.conf.urls import url”

then, the tutorial has you update the file with:

urlpatterns = [
path(’’, views.index, name=‘index’),
]

This created the following error:
NameError: name ‘path’ is not defined

I couldn’t find anything specifically on stackexchange or google but Django docs mention path function is new in v2.0:
https://docs.djangoproject.com/en/2.0/ref/urls/ and they have this for the import statement “from django.urls import include, path”.

I updated my implementation with that(minus the include part) and then verified with what you have in your github.

This resolved my issue. Just bringing it to your attention in case maybe you wanted to add this into the tutorial.

Thanks,

don


(Hamish Willee) #12

Hi Don,

Thanks for reporting this. I updated both the MDN docs and the github at the same time, but there may have been some overlap. I searched on import urlin MDN but did not find this.

I suspect you and I were both working on the docs at the same time so you picked up docs that were only half updated.

Regards
Hamish


(Don Wagner) #13

Hi @hamishwillee, in Django Tutorial Part 9: Working with forms, there is a reference to:

“from django.core.urlresolvers import reverse” in the view.py code which gave this error:

“ModuleNotFoundError: No module named ‘django.core.urlresolvers’”

In the Django 2.0 release notes they recommend using this instead: django.urls

That fixed my error. I’m all good. Just fyi.

best regards,

don


(Hamish Willee) #14

I thought I’d caught all those cases! This was fixed in docs on Jan 16 and I’ve just checked that the error was not present in Github.

Thanks very much.!