Django admin custom view error: invalid literal for int () with base 10

I am trying to create a custom view in Django admin. I am reading from this site, Simple Django Admin Preview , but I have a problem:

ValueError: invalid literal for int() with base 10: '13/preview'

      

Here is my url.py:

url(r'^admin/diligencias/diligencia/(?P<object_id>\d+)/preview/$','preview'),

      

Here is my view.py:

@staff_member_required
def preview(request, object_id):
   return object_detail(request, object_id=object_id,queryset=Diligencia.objects.all(), template_object_name = 'diligencia', )

      

What does this error mean?

+2


source to share


3 answers


The request is not picked up by this URLconf, but the default is admin, which expects everything after the application / model is an integer primary key value.



You may need to move the URL up in the list of URLs so that it goes to the one that contains the admin URLs.

+4


source


What Gabriel says is wrong. I guess the problem is that your view happens after other admin views in URLConf, so this url falls into the trap that Django amdin uses "13 / preview" may be a valid PK, so you should move that url -address over other administrative ones.



+1


source


def importnum():
    n1 = int(raw_input ("enter 1st number?"))
    n2 = int(raw_input ("enter 1st number?"))
    return n1+n2

def main():
    n3=importnum()
    print n3*1/2
      

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      

Run codeHide result


-2


source







All Articles