模板不存在django

时间:2017-03-21 11:05:05

标签: python django python-2.7

我所做的是将多个应用程序放入另一个应用程序。我让他们通过名称系统互相交谈。我仍然需要为数据库做外键和所有操作。

但是我在couresapp上的urls.py中有一条路线,并且有相同渲染的视图,并将我带到了该页面。当我单击成功页面上的目录按钮时,它会向我显示无法找到页面的错误。

希望第二双眼睛可以看到并解决这个问题:

urls.py for courses app

from django.conf.urls import url
from . import views

urlpatterns = [
  url(r'^$', views.index, name= 'index'),
  url(r'^user$', views.create, name='success'),
  url(r'^usercourses$', views.usercourses, name='usercourses')
]

views.py for courses app

def usercourses(request):


    context ={

        "courses": User.objects.all(),

    }

    return render (request, "coursesapp/users_courses.html", context )

html for coures app

   <body>
        <form class="" action="{% url 'courses:usercourses' %}" method="post">

      <p>  Test <option value="{{user.course_name}}"></option> Test
        Test <option value="{{user.course_name}}"></option> Test


            <input type="submit" name="" value="Add">
        </form>

  {% for user in courses%}
     <p>{{user.course_name}} {{user.description}} {{created_at.description}}</p>
      {% endfor%}

    </body>

html,用于登录应用中成功页面中的表单,该表格将我带到了课程应用

    <form class="" action="{% url 'courses:usercourses' %}"  method="post">
            {% csrf_token %}
        <input type="submit" name="Logout" value="Catalog">
    </form>

</html>

回溯抱歉使用此

Template loader postmortem
Django tried loading these templates, in this order:

Using engine django:
    * django.template.loaders.app_directories.Loader: C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\django2\multiapps\multiapps\apps\coursesapp\templates\coursesapp\users_courses.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\django2\multiapps\multiapps\apps\logReg\templates\coursesapp\users_courses.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\django2\multiapps\multiapps\apps\manyapps\templates\coursesapp\users_courses.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\contrib\admin\templates\coursesapp\users_courses.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\contrib\auth\templates\coursesapp\users_courses.html (Source does not exist)



Traceback:

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\core\handlers\exception.py" in inner
  42.             response = get_response(request)

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\django2\multiapps\multiapps\apps\coursesapp\views.py" in usercourses
  34.   return render (request, "coursesapp/users_courses.html", context )

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\template\loader.py" in render_to_string
  67.         template = get_template(template_name, using=using)

File "C:\Users\dbhol\Desktop\DojoAssignments\Python\myenvirnoments\djangoENv\lib\site-packages\django\template\loader.py" in get_template
  25.     raise TemplateDoesNotExist(template_name, chain=chain)

Exception Type: TemplateDoesNotExist at /courses/usercourses Exception Value: coursesapp/users_courses.html

2 个答案:

答案 0 :(得分:0)

问题的答案是课程中的额外内容

答案 1 :(得分:0)

在views.py目录中,将自C:之后的路径放到模板文件夹中,并使用双反斜杠*

*因为\ u是Unicode转义

 return render(request,"C:\\Users\\You\\templates\\test.html",{})