URLS Django无法正常工作

时间:2017-05-02 19:50:39

标签: python django

我正在尝试创建一个用户表单,然后将输入发布到数据库模型。但是我不断收到此错误消息

找不到页面(404) 请求方法:GET 请求网址:http://127.0.0.1:8000/hiresite/Recruiter 使用recruitment.urls中定义的URLconf,Django按以下顺序尝试了这些URL模式:

^ hiresite ^ $ [name =' index']

^ hiresite ^ Recruiter $ [name =' Recruiter']

^管理员/

当前网址,hiresite / Recruiter,并不匹配其中任何一个。

我有点困惑,因为我可以看到上面的网址招聘人员,但我收到错误消息。非常感谢您的帮助。

1.这是我的Urls.py for the app

from django .conf.urls import url

from. import views

urlpatterns = [
    url(r'^$',  views.index, name='index'),
    url(r'^Recruiter$',  views.Recruiter, name='Recruiter')

]

2.这是我的Urls.py项目

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^hiresite',  include('hiresite.urls')),
    url(r'^admin/', admin.site.urls),
]

3.这是Url Recruiter的视图

def Recruiter(request):
    if request.method == 'POST':
        form = register_job(request.POST)
        if form.is_valid():
            title = request.POST.get('title', ' ')
            description = request.POST.get('description', ' ')
            salary = request.POST.get('salary', ' ')
            reference = request.POST.get('reference', ' ')


            user_obj = jobsearch(title=title, description=description, salary=salary, reference=reference)
            user_obj.save()

            return render(request, 'hiresite/Recruiter.html', {'user_obj ': user_obj, 'is_registered': True})
        else:
            form = register_job()
            return render(request, 'hiresite/Recruiter.html', {'form': form})

4.这是Url招聘人员的views.py文件中使用的Html模板文件

!DOCTYPE html>
<html lang="en">
<head>
<title>Learning Html the Hard way</title>
<meta  charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
{% load staticfiles %}
<link rel='stylesheet' href=  " {% static 'css/bootstrap.min.css' %}" type = 'text/css'/>    
</head>
<body>



 <form action="{% url 'hiresite:Recruiter' %}" method="post">
    {% csrf_token %}
   {{ form }}
    <input type="submit" value="Submit">
    </form>

</body>
</html>

1 个答案:

答案 0 :(得分:4)

转换此行:

url(r'^hiresite',  include('hiresite.urls')),

到这一行:

url(r'^hiresite/',  include('hiresite.urls')),