Caffeinatedwolf
Caffeinatedwolf

Reputation: 1307

Django View Error

I am getting the following error

Django Version:     1.4
Exception Type:     ViewDoesNotExist
Exception Value:    

Could not import ratings.views.HotelRating. View does not exist in module ratings.views.

but here is my views.py

from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from ratings.models import Hotel_Rating, Restaurant_Rating, Cafe_Rating, Pastry_Rating
from services.models import *
from ratings.forms import Hotel_Rating_From
from django.template import RequestContext

def HotelRating(request):
    if request.method == 'POST':
        form = Hotel_Rating_From(request.POST)
        if form.is_valid():
            user_id = form.cleaned_data['user_id']
            hotel_id = form.cleaned_data['hotel_id']
            user = User.objects.get(id = user_id)
            hotel = Hotel.objects.get(id = hotel_id)
            review = Hotel_Rating(hotel_id = hotel.id, user_id = user.id, overall_rating = form.cleaned_data['overall_rating'], service = form.cleaned_data['service'], cleanliness = form.cleaned_data['cleanliness'], location = form.cleaned_data['location'], rooms = form.cleaned_data['rooms'], restaurant = form.cleaned_data['restaurant'], room_service = form.cleaned_data['room_service'], price = form.cleaned['price'], comment = form.cleaned_data['comment'])
            review.save()
            return HttpResponseRedirect('/')
        else:
            form = Hotel_Rating_From(request.POST)
            return render_to_response('hotelreview.html', {'form': form}, context_instance = RequestContext(request))

and here is my urls.py file

urlpatterns = patterns('',

    url(r'^admin/', include(admin.site.urls)),
    (r'^register/$', 'reviewers.views.ReviewerRegistration'),
    (r'^hotelrating/$', 'ratings.views.HotelRating'),
    (r'^login/$', 'reviewers.views.LoginRequest'),

)

I dont know what i did wrong, I have added the ratings app in the INSTALLED_APPS in settings.py.

Upvotes: 0

Views: 258

Answers (2)

eric brelsford
eric brelsford

Reputation: 133

Have you stripped ratings/views.py down to the simplest views file it could be? If you can get it working with a very simple view, work up from there to what you have now.

Also, please consider following PEP8 when naming your functions (HotelRating would become hotel_rating) and classes. It will make it easier on anyone you share code with, including this site!

Upvotes: 1

scoopseven
scoopseven

Reputation: 1777

You probably have a circular import. Move your import statement inside your def to see if that helps.

def HotelRating(request):
    from ratings.models import Hotel_Rating

Upvotes: 2

Related Questions