Python Indentation error - django

I have created a project called class , and an application called students
when I write views,
I have to use
items = class.objects.all()
which is giving me error :(
please tell me way to overcome the error without changing my project name..
Thanks :)

I think you'll have to rename it. 'class' is a keyword in python.
http://docs.python.org/reference/lexical_analysis.html#keywords

Related

How can I fix the internal error in Django?

I don't have a lot of experience in Django and I am a fairly green developer. When I run the localhost I keep getting a Internal Error. I have tried most of the solutions to similar problems here and none of them works. Can anyone help me? The code is not mine so I don't want to alter it as such either.
Here is a picture of the errors I keep getting:
The only thing you can do without altering the code is to enter the value "shop_all_art" in the HomePage table in the database.
Do not share code via images. You should also share the related code.
Your stacktrace clearly says, that Python is not able to access first element of HomePage.objects.filter(value='shop_all_art') in file bidgala/bidgala/pages/views.py. all_art_img is most probably empty.
Looks like all_art_img is empty.
you should check if a Query has any elements before with a method such as
if all_art_img.exists():
all_art_img[0]

Uncaught TypeError: Cannot read property 'calcOnDemand' of null

I'm getting this error when I click outside the spreadsheet, after creating a new blank file from the File tab
What is the problem in this?
Thank you for using SpreadJS.
It is difficult to know exactly what is going on based on your description. Do you have a simple code that you can share that replicates the issue.
Just in case, you can set the calcOnDemand option using spread.options.calcOnDemand = false; where spread is the name of your spreadJS instance.
Grapecity SpreadJS Team

Mongoid 4 finding embedded documents by ID

I have a project that is my first serious dive into Mongoid.
I saw a tip to use the following command:
Parent.where('childrens._id' => Moped::BSON::ObjectId(params[:id])).first
But this doesn't work. Error message was:
NameError: uninitialized constant Moped::BSON
I found that BSON is no longer included, so I added it to my Gemfile, as well as Moped. Then, I did another fix I found (placing Moped::BSON=BSON in application.rb).
This still didn't work, but the error changed to:
NoMethodError: undefined method `ObjectId' for BSON:Module
So I am assuming that this method got deprecated or something. Does anyone have any other tips?
Just to be clear, I am finding myself in the situation where I want to sort embedded documents using jquery-sortable. This requires me to update them in the database, but the serialize from that doesn't include the parent document in the hash. So I figured I'd try to get it on the back end using an ID from the embedded document. That is why I need it.
Thanks again for any help you can provide.
Try simply:
Parent.where('childrens._id' => params[:id]).first
I have solved the question though this won't be of much help to people in the future. The requirements have changed and now I am using human-readable strings as IDs to assist in friendly URLs and some other stuff.
Therefore, I don't have any issues with ObjectIds. Cortex's solution should (from what I have read) work for dealing with ObjectIds but I cannot verify it now.

What is the proper way to append view/component to existing view

I have been trying to add a component within a view, I could do it but I am getting some warning message as well like "DEPRECATION: Using the defaultContainer is no longer supported". There is a related post here : emberjs append works but raises Assertion Failed error but not sure what I am doing wrong. Here is my jsbin link : http://jsbin.com/tuwanava/1/
Your help will be very much appreciated. Thanks.
Use
sticky.pushObject(App.ConfirmDeleteComponent.create());

Regex in RedirectRoute not working correctly

I have looked into how to use a regex within a RedirectRoute using webapp2. I have tried formatting it the way it says to do so here: http://webapp-improved.appspot.com/guide/routing.html#the-url-template and I still cannot get my regex to work. Here is what I have:
RedirectRoute('/book/<bookId:([0-9]+)><title:(.*)>',handlers.book,name='book')
the call for this is:
self.redirect_to('book/%s_%s' %(bookId,title))
and an example of the url I am expecting is:
book/5907332378656768_The-Wizzard-of-Oz
When I run my app I get the following error:
Error: "Route named u'book/5907332378656768_The-Wizzard-of-Oz' is not defined.
Any help would be greatly appreciated.
EDIT:
Hey everyone! Thanks to Brent's response I was able to fix the problem.
I had to change self.redirect_to('book/%s_%s' %(bookId,title))
to the following: self.redirect('book/%s_%s' %(bookId,title))
Thank you everyone for your help!
A Google search for webapp2 error route "is not defined" finds the Webapp2 source code. That error message is in the method default_builder() which is called from redirect_to(). That method looks for the name field ('book' in this case). Maybe you meant to call redirect() instead?
I think you can leave the parentheses off the patterns:
RedirectRoute('/book/<bookId:[0-9]+><title:.*>',handlers.book,name='book')