通用详细信息视图DetalleProyecto必须使用URLconf中的对象pk或子弹调用

问题描述

我正在尝试建立一个视图,向我显示记录的详细信息,但是我在添加pk或slug时遇到了麻烦,我是python的新手。

任何帮助将不胜感激

它向我发送的错误消息如下,

在/ buscar /的noreverseMatch 找不到带有参数“('',)”的“ detalle_obra”。尝试了1个模式:['detalle /(?P [0-9] +)/ $']

我也尝试使用get_absolute_url解决它,但它只返回相同的屏幕

#Models.py

`

class Documento(models.Model):
    Num = models.AutoField(primary_key=True)
    doc = models.CharField(max_length=300,blank=True,null=True)
    Adjunto = models.FileField(upload_to='project',null=True)
    LOPSRMEP = models.CharField(max_length=50,null=True)
    Adjunto_lop = models.FileField(upload_to='project',null=True)
    RLOPSRMEP = models.CharField(max_length=50,null=True)
    Adjunto_rlo = models.FileField(upload_to='project',null=True)
    etapa = models.ForeignKey(Etapa,on_delete=models.CASCADE)
    CeCo = models.ForeignKey(Obra,on_delete=models.CASCADE)
        
    creado = models.DateTimeField(auto_Now_add=True)
    modificado = models.DateTimeField(blank=True)

    


    
    def __str__(self):
        return self.doc

#urls.py

from django.urls import path
from .views import HomePageView,DetalleProyecto#,detalle
from core import views

app_name = 'libro'


urlpatterns = [
    path('',HomePageView.as_view(),name="home"),#path('catalogo/',CatalogoPageView.as_view(),name="catalogo"),path('busqueda/',views.busqueda,name="busqueda"),#   path('documento/<slug>/',views.DetalleProyecto.as_view(),name='detalle_obra'),path('detalle/<int:pk>/',DetalleProyecto.as_view(),path('buscar/',views.buscar),]

#views.py

def buscar(request):

    if request.GET["srch"]:
        ce=request.GET["srch"]
        et=request.GET["etapa"]
        res=Documento.objects.filter(CeCo__CeCo=ce,etapa=et).order_by('modificado')
        return render(request,"core/busqueda.html",{"res":res,"query":ce})
    else:
        
        return render(request,"core/invalido.html")

'''def detalle(request,slug):
    documento = Documento.objects.get(slug=slug)

    context = {
        'documento': documento
    }

    return render(request,'core/detalle_obra.html',context) 
'''
class DetalleProyecto(DetailView):
    template_name = 'core/detalle_obra.html'
    model = Documento

#html

     {% for res in res %}
      

        <td height="25">{{res.Num}}
<!--    <td>{% if res.Adjunto %} <a href="{{ res.get_absolute_url }}"> {{res.doc}}</a> {% endif %}       --> 
        <td>{% if res.Adjunto %} <a href="{% url 'libro:detalle_obra' documento.pk %}"> {{res.doc}}</a> {% endif %} 
        <td>{% if res.Adjunto_lop %} <a href="{{ res.Adjunto_lop.url }}">{{res.LOPSRMEP}}</a> {% endif %}
        <td>{% if res.Adjunto_rlo %} <a href="{{ res.Adjunto_rlo.url }}">{{res.RLOPSRMEP}}</a> {% endif %}
        

        
                  
      
      <tr>
      {% endfor %}
      </table>
      </body>
      </html>
          
      

{% endblock %}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...