Reputation: 460
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?
Upvotes: 1
Views: 83
Reputation: 405
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?
Upvotes: -2
Reputation: 5819
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'),
Upvotes: 3