1

I'm building a little web server using django but I keep getting 'str' object has no attribute 'regex' in my template where it says {% url 'signup' %} and {% url 'login' %}. I guess this will be something to do with URL binding, or probably me not having imported the right module that is needed to refer to a URL by its name attribute. But I can't figure a way around this. Thanks in advance.

Template

{% include "header.html" %} 
<div class="container">
    <div class="page-header"><h3>로그인</h3></div>
    <form method="post" action="{% url 'login' %}" role="login">
        {% csrf_token %}
        <div class="form-group">
            <label>아이디</label>
            <input type="text" name="username" placeholder="아이디를 입력하세요" class="form-control" />
        </div>
        <div class="form-group">
            <label>비밀번호</label>
            <input type="password" name="password" placeholder=" 암호를 입력하세요" class="form-control" />
            <input type="hidden" name="next" value="/" />
        </div>
        <div class="form-group">
            <div class="btn-group pull-right">
                <input type="submit" value="로그인" class="btn btn-primary"/>
                <a href="{% url 'signup' %}" class="btn btn-default">가입하기</a>
            </div>
        </div>
    </form>
</div>
{% include "footer.html" %}

Views.py

from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from docx import Document
from exam.models import *

def login(request):
    return render(request, 'login.html')

def signup(request):
    try:
        if request.session["error"]:
            error_message = request.session["error"]
            del request.session["error"]
    except KeyError:
        error_message = None

    context = {
        "error_message" : error_message
    }
    return render(request, "signup.html", context)


def signup_submit(request):
    try:
        username = request.POST["username"].strip()
        password = request.POST["password"].strip()
        password_confirm = request.POST["password_confirm"].strip()
        full_name = request.POST["full_name"].strip()
        student_num = request.POST["student_num"].strip()

        if username and password and password_confirm and full_name and student_num:
            user = User(username=username, full_name=full_name, student_num=student_num)
            user.set_password(password)
            user.save()
            return redirect("index")
    except KeyError:
        request.session["error"] = "올바른 요청이 아닙니다."
        return redirect("signup")
    else:
        request.session["error"] = "입력한 정보가 올바르지 않습니다."
        return redirect("signup")

URLS.py

from django.conf.urls import include, url, patterns
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'),
    url(r'^signup/$', 'exam.views.signup', name='signup'),
    url(r'^signup/submit/$', 'exam.views.signup_submit', name='signup_submit'),

Error Traceback:

AttributeError at /
'str' object has no attribute 'regex'
Request Method: GET
Request URL:    http://192.168.56.101:8000/
Django Version: 1.7.6
Exception Type: AttributeError
Exception Value:    
'str' object has no attribute 'regex'
Exception Location: /home/web/venv/lib/python3.4/site-packages/django/core/urlresolvers.py in _populate, line 282
Python Executable:  /home/web/venv/bin/python
Amit Kumar Gupta
  • 17,184
  • 7
  • 46
  • 64
Bossam
  • 744
  • 2
  • 9
  • 24

0 Answers0