语法错误,DEBUG在urls.py中显示错误?

时间:2015-12-27 06:37:05

标签: python django url views django-urls

所以,我很困惑,一切都在我的应用程序中完美运行,我做了一些更改,然后我在我的应用程序中还原。但是,这导致我的登录页面出错:

SyntaxError at /login/
invalid syntax (views.py, line 41)
Request Method: GET
Request URL:    http://X.X.X.X:8000/login/
Django Version: 1.8
Exception Type: SyntaxError
Exception Value:    
invalid syntax (views.py, line 41)
Exception Location: /path/to-app/project-name/app (same name as project)/urls.py in <module>, line 22

这是我的url.py文件:

from django.conf.urls import *
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from import views
import overtime.views
import schedule.views

urlpatterns = [ 
url(r'^admin/', include(admin.site.urls)),
url(r'^login/', views.login_user),
url(r'^index/', views.index),
url(r'^$', views.index, name='index'),
url(r'^login_success/$', views.login_success, name='login_success'), 
url(r'^overtime/',include('overtime.urls')),
url(r'^schedule/',include('schedule.urls')),       
url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page':     '/login'}),
]

我尝试了很多视图导入,但都导致了相同的语法错误:

来自。导入视图 来自MonolithEmployee导入* 导入视图 import MonolithEmployee.views

其中每一个都会导致语法错误。

这可能是其他地方的问题吗?

这是它似乎引用的视图:

# user login
@login_required
def login_user(request):
    if request.user.is_authenticated():
        pass
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                return redirect("login_success")
        else:
            form = LoginForm()
            context = {'form': form}
            return render_to_response('login.html', context, context_instance=RequestContext(request))
    else:
        ''' user is not submitting the form, show the login form '''
        form = LoginForm()
        context = {'form': form}
        return render_to_response('login.html', context,     context_instance=RequestContext(request))

def login_success(request):
    """
    Redirects users based on the group they are in 
    """
    if request.user.groups.filter(name="BAML").exists():
        return redirect("")
    else:
        return redirect("index")

def logout_user(request):
    logout(request)
    return HttpResponseRedirect('/login/')

def index(request):
    context = {}
    return render_to_response('index.html', context, RequestContext(request))

def index_BAML(request):
    context = {}
    return render_to_response('.html', context, RequestContext(request

1 个答案:

答案 0 :(得分:1)

这是你的代码:

def index_BAML(request):
    context = {}
    return render_to_response('index_BAML.html', context, RequestContext(request

你刚刚离开了最后一个对象:

def index_BAML(request):
    context = {}
    return render_to_response('index_BAML.html', context, RequestContext(request))