What I was asking was do you have an example of it being done with sockets?
What do sockets have to do with overriding a method?
Nothing. You’re still trying to mix two completely separate issues.
What you do inside an overridden method has nothing to do with how that method is overridden. That’s the point I keep trying to make here.
Forget about sockets for a moment. Create a method that overrides your class’ form_valid method and prints the message “Hello world.”
Then, replace that print statement with your socket code to send a message to the robot.
I did the override and added the code however I am getting a connection error. I added all of the code here, if you could help that would be awesome.
python - Add Sockets To Django View For Contact With Robot - Stack Overflow
I thought you were opening a connection to the robot? The code you’ve posted is for a socket server, not a socket client.
I thought the error would be from the server side? I will add the client side
If your code needs to initiate the connection to the robot, your Django “server” is the “client” to the robot.
You don’t need to add the client code, you need to remove the server code and replace it with the client code to initiate the connection to the robot.
Forget Django for the moment - do you have any working Python code to communicate with the robot? If so, please post it here.
Why would the django side be the client? The website is SENDING the information. Currently the two things are completely separate
Again, forget Django for the moment - do you have any working Python code to communicate with the robot? If so, please post it here.
No, I have the code for the robot to function written but nothing for it to communicate that is what I am trying to do now
Ok, then I strongly suggest you work on this outside of Django until you have a stand-alone script that is capable of sending a command to the robot.
I have the client and server side code written, I just don’t know how to implement them.
I’m guessing there’s a translation issue here. What code do you have written?
Oh, I understand now what you mean about the client being what I should implement with Django, I will give that a try.
Ok, I got some new errors. I added them to the post
Cool, now review my previous answer at Add Sockets To Django View For Contact With Robot - #26 by KenWhitesell
I did replace it with the client code, and I am running the server code on the robot now.
I am getting an error when I replaced the form_valid method of my view. Any reason why this would happen?
The view dashboard.views.RobotDetail didn't return an HttpResponse object. It returned None instead.
I think the error message pretty much explains it.
A view is supposed to return an HttpResponse object. Your view doesn’t - it’s returning None.
See the docs on Writing views.
I added a return render but because it is a CBV I can’t get request in. Any ideas why?
Typically, that’s not what you use to return from a GCBV.
When a form is submitted, you generally will return a redirect to a URL. Yes, it could be the URL of the current page, in which case the browser will get the same page. Or it could be a different page. See how the form_valid function works in the standard GCBVs in the Classy CBV page.
(Now, this all is not to say that the request object isn’t available in the object - it’s just that if you’re interested in using the GCBVs the way they’re intended to be used, you don’t need it.)