Django syntax error in urls.py - django

in my website's main urls.py file, I am trying to add this line:
url(r'^account/',include('accounts.urls', namespace='accounts')),
after adding the line, my file looks like this:
from django.conf.urls import patterns, include, url
from invest1.views import *
#to enable admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'invest1.views.home', name='home'),
url(r'^about/$', 'invest1.views.about', name='about'),
url(r'^contact/$', 'invest1.views.contact_us', name='contact'),
url(r'^account/', include('accounts.urls', namespace='accounts')),
url(r'^profile/', include('profiles.urls', namespace='profiles')),
url(r'^post/', include('posts.urls', namespace='posts')),
#uncomment to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
#to enable admin
url(r'^admin/', include(admin.site.urls)),
)
no matter what I do to the file, I get the error
SyntaxError at /
invalid syntax (urls.py, line 18)
with the accounts line commented out, the website runs. but no matter where I put the line, it always gives me the same error with the same line number. I've even retyped the whole thing to make sure it's not some illegal whitespace character. I feel like I'm missing something really trivial...what's causing the error?

The problem is probably in one of the other urls.py (e.g. accounts.urls).

Related

Django {% url %} behaving strangely

Can someone explain why this works:
<li>HOME</li>
<li>PROJECTS</li>
While this doesn't:
<li>HOME</li>
<li>PROJECTS</li>
I get a 500 error with ImportError at /index/ No module named project however I'm not trying to import project anywhere. (I am importing Project, which has been importing fine for days, and works fine when I don't use {% url %} style links). I've seen a number of answers here and blog posts elsewhere suggesting that {% url %} is a bad idea. I'm happy to stop using them if necessary, but for the life of me can't see where the error is coming from.
Contents of urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.views.static import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^index/', 'projects.views.index', name='index'),
url(r'^login/', 'project.views.login', name='login'),
url(r'^project/(?P<project_id>\d+)/$', 'projects.views.project', name='project'),
url(r'^project/', 'projects.views.project', name='project'),
url(r'^sched/(?P<project_id>\d+)/$', 'projects.views.schedule'),
url(r'^luminaires/(?P<project_id>\d+)/$', 'projects.views.luminaires'),
url(r'^luminaire/(?P<project_id>\d+)/(?P<luminaire_id>\d+)/$', 'projects.views.luminaire'),
url(r'^deleteproject/(?P<project_id>\d+)/$', 'projects.views.deleteproject', name = 'deleteproject'),
url(r'^admin/', include(admin.site.urls)),
# Examples:
# url(r'^$', 'relume.views.home', name='home'),
# url(r'^relume/', include('relume.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes':True}),
)
After looking at your urls.py file, it seems you have a typo in the login's line of urls where you have used project instead of projects.

Redirect after login not working

I've been searching around but can't figure out why the redirection after login is not working as expected.
I successfully login at http://localhost:8000/accounts/login/. After that I'm always redirected to http://localhost:8000 no matter if I use settings.py variable LOGIN_REDIRECT_URL or if I leave it completely out.
# urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^grappelli/', include('grappelli.urls')),
url(r'^$', 'myapp.views.home', name='home'),
url(r'^home/$', 'myapp.views.apphome', name='apphome'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('registration.backends.default.urls')),
(r'^admin/', include("massadmin.urls")),
)
I don't know where I should start looking for a problem. Any ideas? Is there some settings I'm missing here? Any other files I should include to help debug the problem?
Check your form action! (glad I could help :) )

django gets a 404 page when I try to access django-registration

Hello and thank you in advance,
When I installed django-profiles and django-registration. I believe I followed a tutorial correctly on how to configure them:
http://agiliq.com/books/djenofdjango/chapter5.html#reusable-apps
Now when I try to access website.com/accounts I get a 404 page:
Using the URLconf defined in acme_p.urls, Django tried these URL patterns, in this order:
^$
^accounts/
^admin/doc/
^admin/
The current URL, accounts, didn't match any of these.
My urls files look like this:
#acme_p urls - Django Project
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('user_prof.urls')),
# Examples:
# url(r'^$', 'acme_p.views.home', name='home'),
# url(r'^acme_p/', include('acme_p.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
user_prof urls.py - Django App one level below project mentioned above
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^login/$', 'auth.views.login_user'),
(r'^accounts/', include('registration.urls')),
# (r'^accounts/', include('registration.backends.default.urls')),
)
Thank you for you help.
dp
(r'^accounts/', include('registration.urls')), should be in the root urls.py not the app urls.py
There is no website.com/account in the configuration, there is only website.com/account/(more) where (more) has the rest of the url that is given to the django-registration module. You could try website.com/account/login/ for example to check if the django-registration module is working.
Also you should just put those on the root urls.py file.

django url regex doesn't match

Using Django 1.3 with development server
I try to connect with: http://127.0.0.1:8000/lang/en
The answer is:
Using the URLconf defined in
pruebas.urls, Django tried these URL
patterns, in this order:
^admin/
^correo/$
^login/$
^lang/(?P\w+)/$
^site_static/(?P.*)$
The current URL, , didn't match any of
these.
And this is my "urls.py":
from pruebas import settings
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'pruebas.views.home', name='home'),
# url(r'^pruebas/', include('pruebas.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
(r'^correo/$', 'mailclient.views.index'),
(r'^login/$', 'kusers.views.klogin'),
# Language change
(r'^lang/(?P<lang_code>\w+)/$', 'kusers.views.lang'),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),)
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
def lang(request, lang_code):
request.session['django_language'] = lang_code
return HttpResponseRedirect( "/" )
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
If you put a trailing slash on the url it will work, as in:
http://127.0.0.1:8000/lang/en/

Django Admin application no working on URL

In my urls file I have configured the Django admin application to run off the url /adminDJ/. However it doesn't run. It loads up my own admin stuff. Here is my urls.py:
(r'^admin/add/member/$', 'astonomyStuff.attendance.views.newMember'),
(r'^admin/add/$', 'astonomyStuff.attendance.views.addPage'),
(r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^adminDJ/$', include(admin.site.urls)),
(r'^talks/$', 'astonomyStuff.attendance.views.talksIndex'),
(r'^talks/past/$', 'astonomyStuff.attendance.views.viewAllTalks'),
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'),
(r'^members/(?P<member_number>[^/]+)/$', 'astonomyStuff.attendance.views.viewMember'),
(r'^members/(?P<member_number>[^/]+)/delete$', 'astonomyStuff.attendance.views.deleteMember'),
(r'^admin/add/talk/$', 'astonomyStuff.attendance.views.newTalk'),
(r'^talks/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewTalk'),
(r'^attendance/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewAttendance'),
(r'^databrowse/(.*)', databrowse.site.root),
(r'^adminDoc/doc/', include('django.contrib.admindocs.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^accounts/profile/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^admin/add/attendance/$', 'astonomyStuff.attendance.views.addAttendance'),
(r'^members/(?P<member_number>[^/]+)/edit$', 'astonomyStuff.attendance.views.editMember'),
(r'^public/talks/$', 'astonomyStuff.attendance.views.publicViewTalks')
I have rearranged the order to see if this was the problem but that's not fixed it. Must the django admin application run on /admin/?
Edit
I have had the admin application working before just to let you know it only broke when I played around with the urls.
Edit 2
Here is my complete urls.py:
from django.conf.urls.defaults import *
from astonomyStuff.attendance.models import Member
from astonomyStuff.attendance.models import Non_Member
from astonomyStuff.attendance.models import Talk
from astonomyStuff.attendance.models import Event_Attendance
from django.contrib import admin
from django.contrib import databrowse
admin.autodiscover()
admin.site.register(Member)
admin.site.register(Non_Member)
admin.site.register(Talk)
admin.site.register(Event_Attendance)
databrowse.site.register(Member)
databrowse.site.register(Non_Member)
databrowse.site.register(Talk)
databrowse.site.register(Event_Attendance)
urlpatterns = patterns('',
# Example:
# (r'^astonomyStuff/', include('astonomyStuff.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/add/member/$', 'astonomyStuff.attendance.views.newMember'),
# (r'^admin/add/$', 'astonomyStuff.attendance.views.addPage'),
# (r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^admin/$', include(admin.site.urls)),
(r'^talks/$', 'astonomyStuff.attendance.views.talksIndex'),
(r'^talks/past/$', 'astonomyStuff.attendance.views.viewAllTalks'),
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'),
(r'^members/(?P<member_number>[^/]+)/$', 'astonomyStuff.attendance.views.viewMember'),
(r'^members/(?P<member_number>[^/]+)/delete$', 'astonomyStuff.attendance.views.deleteMember'),
# (r'^admin/add/talk/$', 'astonomyStuff.attendance.views.newTalk'),
(r'^talks/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewTalk'),
(r'^attendance/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewAttendance'),
(r'^databrowse/(.*)', databrowse.site.root),
(r'^adminDoc/doc/', include('django.contrib.admindocs.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^accounts/profile/$', 'astonomyStuff.attendance.views.adminPage'),
# (r'^admin/add/attendance/$', 'astonomyStuff.attendance.views.addAttendance'),
(r'^members/(?P<member_number>[^/]+)/edit$', 'astonomyStuff.attendance.views.editMember'),
(r'^public/talks/$', 'astonomyStuff.attendance.views.publicViewTalks'),
)
Not this (r'^adminDJ/$', include(admin.site.urls)),
But this (r'^adminDJ/', include(admin.site.urls)), ##note, no $ in the regex
Remember folks, gotta check your regexes...
This is probably nothing but it caught my eye. From the first snippet:
(r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^adminDJ/$', include(admin.site.urls)),
And the second snippet:
(r'^admin/$', include(admin.site.urls)),
Is this how you want it? The first snippet uses ^adminDJ/$ while the second one uses admin/$ opposite include(admin.site.urls).
Are these two files? And are the both used? In that case the first snippet could very well override the second, thereby causing your admin views to show up instead of Django's.