1

I'm having a syntax error with Django (Django 1.8, Python 3.4) in my base URL. Here's the code for ir:

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

from login_vacations import views as login_views

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^login/$', login_views.index, name="login_vacations"),
    url(r'^logout/$', login_views.logout_vacations, name='logout_vacations'),
    url(r'^vacations/', include('vacations_app.urls')),
]

The vacations_app exists on the folder and it does have a urls.py file inside of it. The error is the following:

invalid syntax (urls.py, line 10)

Instead, if i remove the single quotes from the include function, the error will be:

name 'vacations_app' is not defined

If i erase line 10 entirely, the application will work normally. But i do not understand why. The structure on this line is exactly the same as the one on line 7 (the one which includes the admin urls).

The vacations_app/urls.py has the following code:

from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView

from vacations_app import views as vacations_views

urlpatterns = [
    url(r'^$', vacations_views.vacations_public_view, name='vacations_public_view'),
    url(r'^my_vacations/$', vacations_views.my_vacations, name='my_vacations'),
    url(r'^new_vacation/$', vacations_views.new_vacation, name='new_vacation'),
    url(r'^show/(?P<vacation_id>\w+)/$'), vacations_views.show_vacation, name='show_vacation'),
    url(r'^show/(?P<vacation_id>\w+)/add_destination/$'), vacations_views.add_destination_to_vacation, name='add_destination_to_vacation'),
    ]

The full trace of the error can be found here: http://dpaste.com/2A1B6DS

Can someone help me?

6
  • What are the contents of vacations_app/urls.py? Commented Nov 10, 2015 at 16:35
  • did you added vacations_app in installed_apps of settings.py? Commented Nov 10, 2015 at 17:15
  • Can you provide the full traceback for your error? Commented Nov 10, 2015 at 17:21
  • I edited the question to provide more details as you guys asked Commented Nov 10, 2015 at 19:53
  • @Alasdair I edited the question to include it Commented Nov 10, 2015 at 19:58

2 Answers 2

3

It looks like you have two additional close parentheses in your vacations_app/urls.py on lines 10 and 11. Right now you have:

url(r'^show/(?P<vacation_id>\w+)/$'), vacations_views.show_vacation, name='show_vacation'),
url(r'^show/(?P<vacation_id>\w+)/add_destination/$'), vacations_views.add_destination_to_vacation, name='add_destination_to_vacation'),

They should look like:

url(r'^show/(?P<vacation_id>\w+)/$', vacations_views.show_vacation, name='show_vacation'),
url(r'^show/(?P<vacation_id>\w+)/add_destination/$', vacations_views.add_destination_to_vacation, name='add_destination_to_vacation'),
Sign up to request clarification or add additional context in comments.

Comments

-2

Have you added the application (vacations_app) as INSTALLED_APPS in your settings.py? I am also a bit skeptical of your urlpatterns = [] because I have urlpatterns = patterns() on some of my project.

Can you share your settings.py (with identifiable information omitted) if possible?

3 Comments

This should be a comment. In any case, neither of these can be the cause of a syntax error.
Using a list instead of the patterns function is the new preferred way to declare url patterns (cf doc)
@DanielRoseman Ideally I would have commented but I could not because my reputation was 46 when I posted earlier. I think that Joey Wilhelm has hit the nail on its head.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.