from django.db import models
Create your models here.
class Permiso(models.Model):
nombre = models.CharField (max_length=50)
direccion = models.TextField (null = True, blank = True)
from django.db import models
# Create your models here.
class Permiso(models.Model):
nombre = models.CharField (max_length=50)
direccion = models.TextField (null = True, blank = True)
def __str__(self):
return '{}'.format(self.nombre)
class Partida(models.Model):
partida = models.IntegerField(primary_key = True)
descripcion = models.TextField ()
permisos = models.ManyToManyField (Permiso, blank = True)
class Partida(models.Model):
partida = models.IntegerField(primary_key = True)
descripcion = models.TextField ()
permisos = models.ManyToManyField (Permiso, blank = True)
def __str__(self):
return '{}'.format(self.partida)
def Partida_Search(request):
partida = request.GET.get('q','')
context = Partida.objects.get(partida=partida)
return render (request, 'partida/partida_search.html', {'partida': context})
def Partida_Search(request):
partida = request.GET.get('q','')
context = Partida.objects.get(partida=partida)
return render (request, 'partida/partida_search.html', {'partida': context})
esta mi url:
from apps.partida.views import Partida_Search
urlpatterns = [
url(r'^buscar/$', Partida_Search, name='partida_buscar'),
]
from apps.partida.views import Partida_Search
urlpatterns = [
url(r'^buscar/$', Partida_Search, name='partida_buscar'),
]
Partidas arancelarias
{% csrf_token %}<h3>Partidas arancelarias</h3>
<form action="{% url 'partida_buscar' %}" method="get">
{% csrf_token %}
<input type="text" name="q" id ="buscador" value="">
<button style="position:absolute;top:47px;left:375px;"
type="submit" class="btn btn-primary">Buscar</button>
</form>
Soy nuevo en la comunidad...Alguien sabe porque cuando escribo la url /buscar me sale este error:
ValueError at /partida/buscar/
invalid literal for int() with base 10: ''
Request Method: GET
Request URL: http://localhost:8000/partida/buscar/
Django Version: 1.11.11
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: ''
Exception Location: /home/daniel/django-project/aranceles/apps/partida/views.py in Partida_Search, line 36
Python Executable: /usr/bin/python3
Python Version: 3.6.7
Python Path:
['/home/daniel/django-project/aranceles',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Lun, 11 Feb 2019 20:03:57 +0000
ValueError at /partida/buscar/
invalid literal for int() with base 10: ''
Request Method: GET
Request URL: http://localhost:8000/partida/buscar/
Django Version: 1.11.11
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: ''
Exception Location: /home/daniel/django-project/aranceles/apps/partida/views.py in Partida_Search, line 36
Python Executable: /usr/bin/python3
Python Version: 3.6.7
Python Path:
['/home/daniel/django-project/aranceles',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Lun, 11 Feb 2019 20:03:57 +0000