Django模板呈现无反向匹配时出错

时间:2017-03-13 13:15:21

标签: python django

任何人都可以帮我解决这个问题吗?我看到所有与我的问题类似的帖子,但我无法解决这个问题。 错误:

class CommitCreate(CreateView): template_name = 'layout/project_commit_detail.html' model = Commit fields = ['user', 'project', 'branch', 'commit_title', 'commit_body'] success_url = reverse_lazy('git_project:index')

views.py

<div class="container-fluid">
<a href="#demo1" class="btn btn-info btn-block" data-toggle="collapse">Add New Commit</a>
<div id="demo1" class="collapse" >
    <form class="form-horizontal" action="{% url 'git_project:commit_add' project.id %}" method="post" enctype="multipart/form-data">
        {% csrf_token %}
        {% if user.is_authenticated %}
        <label for="user">Commit created by: "{{ user.username }}"</label><br>
        <input id="user" type="hidden" name="user" value="{{ user.id }}">
        <label for="project">Commit for project: "{{ project.proj_title }}"</label><br>
        <input id="project" type="hidden" name="project" value="{{ project.id }}">
        <label for="branch">Branch: </label>
        <select>
            {% for branch in all_branches %}
            <option id="branch" name="branch">{{branch.branch_name}}</option>
            {% endfor %}
        </select><br>
        <label for="commit_title">Commit Title: </label>
        <input id="commit_title" type="text" name="commit_title"><br>
        <textarea id="commit_body" name="commit_body" rows="5" cols="50" placeholder="Commit body..."></textarea><br>
        <button type="submit" class="btn btn-success">Commit</button>
        {% endif %}
    </form>
</div>

html表单

url(r'project/(?P<pk>[0-9]+)/add_commit/$', views.CommitCreate.as_view(), name='commit_add'),

url.py

class Commit(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, default=0)
    project = models.ForeignKey(Project, on_delete=models.CASCADE, default=0)
    branch = models.ForeignKey(Branch, on_delete=models.CASCADE, default=0)
    commit_title = models.CharField(max_length=64)
    commit_body = models.CharField(max_length=16384)
    commit_date = models.DateTimeField(default=timezone.now)

model.py

$('#exampleId').css({"maxHeight":"100px"});

我不知道为什么会这样。谁能帮我?我是Django的新手。 谢谢! :)

0 个答案:

没有答案