Skip to content

Instantly share code, notes, and snippets.

@JuniorLima
Created April 25, 2012 18:18
Show Gist options
  • Save JuniorLima/2491853 to your computer and use it in GitHub Desktop.
Save JuniorLima/2491853 to your computer and use it in GitHub Desktop.
Quando eu entro na notícia com o link, dá certo.
http://localhost:8000/categoria/teste-de-slug
Quando eu coloco '#' no link, a notícia é exibida normalmente.
Caught NoReverseMatch while rendering: Reverse for 'Scope.views.noticiainterna' with arguments '()' and keyword arguments '{'slugnoticia': u'teste-de-slug'}' not found.
Estou achando que o erro está no models na hora de gerar a url na def get_absolute_url.
<div id="bloco">
<a href="{% url Scope.views.noticiainterna slugnoticia=noticias.slugnoticia %}">
<div id="img">
<img src="{{ MEDIA_URL }}{{ noticias.imagemDestaque }}" alt="{{ noticias.titulo }}" width="220" height="154">
</div>
</a>
<p class="chapeu">{{ noticias.chamada }}</p>
<a href="#"><h2 class="titulobloco1">{{ noticias.titulo }}</h2></a>
</div>
class Categoria(models.Model):
nome = models.CharField(max_length=30)
slugcategoria = models.SlugField(max_length=100, blank=True, unique=True)
def get_absolute_url(self):
return reverse('Scope.views.categoria', kwargs={'slugcategoria': self.slugcategoria})
class Noticia(models.Model):
titulo = models.CharField(max_length=100, unique=True)
nomecategoria = models.ForeignKey(Categoria)
slugnoticia = models.SlugField(max_length=200, blank=True, unique=True)
def get_absolute_url(self):
return reverse('Scope.views.noticiainterna', kwargs={'slugnoticia': self.slugnoticia})
(r'^(?P<slugcategoria>[\w_-]+)/(?P<slugnoticia>[\w_-]+)/$', 'Scope.views.noticiainterna'),
def noticiainterna(request, slugcategoria, slugnoticia):
noticias = get_object_or_404(Noticia, nomecategoria__slugcategoria = slugcategoria, slugnoticia=slugnoticia)
return render_to_response('Scope/sub_noticia.html',locals(),context_instance=RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment