使用参数'('',)'和关键字参数'{}'找不到“详细信息”。 1

时间:2017-04-10 18:38:06

标签: python django django-models django-templates django-views

在views.py中,详细信息功能和索引功能

#Popularity_based code
pb = Popularity_based(users, movies)
pb.create()
top_movies = pb.recommend()

#Collaborative_filtering code
cf = Collaborative_filtering(ratings_file,movies)
cf.compute_svd()

#Details of movie code
ia = imdb.IMDb()
url = "http://www.omdbapi.com/?t="


#keys in json string are :
'''
[u'Plot', u'Rated', u'Title', u'Ratings',
 u'DVD', u'Writer', u'Production', u'Actors',
  u'Type', u'imdbVotes', u'Website', u'Poster', u'Director',
   u'Released', u'Awards', u'Genre', u'imdbRating',
    u'Language', u'Country', u'BoxOffice', u'Runtime',
     u'imdbID', u'Metascore', u'Response', u'Year']
'''









def index(request):
    if not request.user.is_authenticated():
        return render(request, 'movies/login.html')
    else:
        user = request.user.id
        #moviez = Film.objects.all()
        #all_pictures = Picture.objects.all()    'all_pictures': all_pictures,
        #return render(request, 'movies/index.html', { 'moviez': moviez})        
        #pb = Popularity_based(users, movies)
        #pb.create()
        #top_movies = pb.recommend()
        return render(request, 'movies/index.html', {'top_movies': top_movies,'user':user})
def detail(request, movie_id):
    if not request.user.is_authenticated():
        return render(request, 'movies/login.html')
    else:
        user = request.user
        #picture = get_object_or_404(Picture, pk=picture_id)
        #getting details from omdbapi
        bb = str(movies.ix[movies['movie_id'] == movie_id ]['title']).split()    
        q = bb.index('Name:')
        bb = ' '.join(bb[1:q])
        item = ia.search_movie(bb)[0]
        print("Name in item is " + str(item))
        name = str(item)        
        ll = name.split()
        #ll = '+'.join(ll)
        movie_url = url + '+'.join(ll)
        movie_url += "&plot=full"
        print movie_url
        content = urllib2.urlopen(movie_url).read()
        jsontopython = json.loads(content)

        #Values passed to details.html file
        plot = jsontopython['Plot']
        writers = jsontopython['Writer']
        producers = jsontopython['Production']
        actors = jsontopython['Actors']
        director = jsontopython['Director']
        awards = jsontopython['Awards']
        runtime = jsontopython['Runtime']
        genre = jsontopython['Genre']

        #movies similar to this movie.
        similar_movies = cf.get_similar_movies(movie_id)
        return render(request, 'movies/detail.html', {'similar_movies':similar_movies,'plot':plot,'writers':writers,'producers':producers, 'actors':actors,'director':director,'awards':awards,'runtime':runtime,'genre':genre,'picture':picture})

这是我的urls.py

urlpatterns = [
   url(r'^$', views.index, name='index'),
   url(r'^register/$', views.register, name='register'),
   url(r'^login_user/$', views.login_user, name='login_user'),
   url(r'^(?P<movie_id>[0-9]+)/$', views.detail, name='detail'),
   url(r'^logout_user/$', views.logout_user, name='logout_user'),
]

这是我的index.html页面

{% for picture in top_movies %}
     <div class="col-sm-4 col-lg-2">
         <div class="thumbnail">
             <a href="{% url 'movies:detail' movie.id %}">
                 <img src="{% static "movies/images/images2/" %}{{picture}}" alt="Hi!" class="img-responsive" />
             </a>
             <div class="caption">
                 <h4>{{ picture }}</h4>
             </div>
         </div>
     </div>
{% endfor %}

这是我的models.py

from django.contrib.auth.models import Permission, User
from django.db import models
from decimal import Decimal


class Picture(models.Model):
    user = models.ForeignKey(User, default=1)
    picture_id = models.IntegerField(default=0)
    picture_title = models.CharField(max_length=500)
    genres = models.CharField(max_length=1000)
    ratings = models.DecimalField(max_digits=10, decimal_places=1)
    picture_logo = models.CharField(max_length=1000, default='/media/noimage.jpg')

    def __str__(self):
        return self.picture_title

我收到NoReverseMatch错误enter image description here 我想显示包含每部电影细节的电影细节。但是我收到了NoReverseMatch错误。

0 个答案:

没有答案