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

标签 python django url view 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'}),
]

我尝试了许多 View 导入的变体,所有这些都导致相同的语法错误:

来自 .导入 View 从 MonolithEmployee 导入 * 导入 View 导入 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

最佳答案

这是您的代码:

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))

关于python - 语法错误,DEBUG 在 urls.py 中显示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34478195/

相关文章:

python - layout = torch.strided 是什么意思?

python - 序列化程序调用显示 TypeError : Object of type 'ListSerializer' is not JSON serializable?

python - 主从 postgresql,具有 django 应用程序的日志记录和监控功能

php - 从 url 中删除路径并添加另一个路径

python - 将索引列表变成列表列表

python - Django 中的 TypedChoiceField 或 ChoiceField

Django模型继承结构

javascript - 如何使用 jQuery 检测 URL 更改

java - URLClassLoader.getResources ("") (空资源名称) 没有给出 jars 的根

python - 在 Dataframe 中查找重复项并返回 1 和 0