0

I have a list of items in an html file as follows:

{% extends 'base.html' %}
{% block Content %}
   <div id="movie_list">
      {% for movie in movies %}
         <p class="movie-title"><a href="/movie/{{ movie.slug }}/">{{ movie.name }}</a> </p>
      {% endfor %}
</div> {% endblock %}

It displays a list of movies name which every item in this list is a link! I try to send a request to server to see a specific movie according to the href attribute in the <a> tag.

The model handles this request is as follows:

def SpecificMovie(request, movie_slug):
    movie = Movie.objects.get(slug=movie_slug)
    context = {'movies': movie}
    return render_to_response('single_movie.html', context, context_instance=RequestContext(request))

It responds to the request according the movie_slug passed into it!

the single_movie.html file is as follows:

{% extends 'base.html' %}

{% block Content %}
  <div id="single_moive">
    <p class="movie-title">Name: {{ movies.name }}</p>

    <p class="movie-title">Des: {{ movies.description }}</p>

    <p class="movie-title">Country: {{ movies.country }}</p>
  </div>
{% endblock %}

and my urlpatterns var is as follows:

urlpatterns = patterns('', 
                   (r'^$', TemplateView.as_view(template_name='index.html')),
                   (r'^admin/', include(admin.site.urls)),
                   (r'^movie/$', 'movie_page.views.MoviesAll'),
                   (r'^movie/(?P<movie_slug>.)/$', 'movie_page.views.SpecificMovie'),
)

But when I click on each item in receive an error saying that there is miss match in the url pattern. An snapshot of the page is as follows: error 404

as you can see everything seems ok! but I don't know what the problem is! I read the following links(link1,link2, link3) but Thanks for any comments.

Community
  • 1
  • 1
Hadi
  • 5,328
  • 11
  • 46
  • 67

1 Answers1

3

The regex (?P<movie_slug>.) matches a single character. You probably want (?P<movie_slug>.+).

Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97
  • 2
    +1 though `.+` is too greedy. A specific regex for slug could be better here `(?P[\w-]+)` – Aamir Rind Jun 11 '14 at 19:30
  • I removed the dot before but the problem didn't solve! Why this happened? – Hadi Jun 12 '14 at 06:13
  • 1
    @Constantine You want to match one or more characters. The dot matches one, and adding the `+` makes it match one or more. Removing the dot makes it match nothing. – Ismail Badawi Jun 12 '14 at 17:28