为什么我的表单模板没有显示在Django项目中

时间:2018-09-18 16:28:40

标签: python html django django-models

所以我是django的新手,我相信这不是一个很好的问题。我正在一个项目中,我有一个供用户使用的表单(用于数据库输入)。它应该在我单击链接后显示;即添加E-Shop,但是,当我单击它时,我仍然停留在同一页面上(即使网址已更改)

重定向链接是这样的:

<li class="nav-item" >
    <a class="nav-link" style="color: #ffffff" href="{%url "main:add-shop"%}">Add E-Shop</a>
</li>

我的views.py文件如下:

def emarket(request):
    if not request.user.is_authenticated:
        return HttpResponseRedirect('/login/')
    emarket = Emarket.objects.all().exclude(verify = False)
    pos = Emarket.objects.values_list('latt', 'lonn')
    a = np.array(pos)
    lat1=[]
    long1=[]
    for i in range(len(a)):
        lat1.append(a[i][0])
        long1.append(a[i][1])
    return render(request, 'main/emarket.html', {"emarket": emarket ,'lat' : lat1 , 'lng':long1 })


class AddShop(CreateView):   #this is my adding shop model
    model = Emarket
    fields = ['name', 'owner', 'city_location', 'description', 'logo', 'latt', 'lonn']
    template_name = "main/shop_form.html"

以下是我的网址配置:

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

app_name = 'main'

urlpatterns = [
    url(r'^home/', views.index, name='index'),    # Home page
    url(r'e-market/', views.emarket, name = 'emarket'),     # rain water 
    url(r'e-market/add-eShop/$', views.AddShop.as_view(), name = 'add-shop'),   # Add an E shop
]

我的表单模板的名称为“ shop_form.html” shop_form.html:

 **<form method="post" novalidate enctype="multipart/form-data" class = "loginBox">
        {% csrf_token %}
            <h2 class = "register-text" style="font-size: 30px;"> Add E-Shop</h2>
            {{ form.as_p }}

        <input class = "register-button" type="submit" name="" value="Add Incubator">

    </form>**

1 个答案:

答案 0 :(得分:1)

您需要终止电子市场网址:

 url(r'e-market/$', ...