Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

My url.py code isn't working in python

Hi,

I am currently trying to create a library webite for my school assignment but I am not knowlegable about python so I am really confused as to how the coding works. I am currently at the process of creating urls and views, but after watching a few tutorials on Youtube, I still can't get my code to work.

There is always an error called -- SyntaxError: EOF while scanning triple-quoted string literal

This is the code I'm having errors with:

from django.contrib import admin
from django.conf.urls import include, url

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url('books/', include('library.urls')),
]

The reason for doing that code is to link this main urls.py file to another urls.py in another location so I do not need to put all my urlpatterns in the main location. And at the same time, I am also importing views to the newly created urls.py file. But I cannot get Python to execute the codes as I need to display words in the website.

Any help would be appreciated. Thanks!

[MOD: added ```python formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

Can you be more specific about the error? I don't see the triple quoted string you mentioned. Also, could you post the full stacktrace error message you are seeing?

1 Answer

Hi there,

Could this be due to the following comma at the end of your array?

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url('books/', include('library.urls')), # <- is that comma needed?
]

Steve.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

Python allows trailing commas in list, set, tuple, and arg_list definitions and it's an accepted practice.

Ah right - not that then! I do recall it in tuples, now you mention it. Python's not really my thing, as you can tell!

No, I don't think so. I tried removing the comma but the error is still there :(

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

Please paste a complete copy of the stacktrace error you see