On Sat, Jun 25, 2011 at 1:42 PM, CareerDhaba tech <t...@careerdhaba.com>wrote:
> Hey, > > Thanks Karen for the reply. I have been trying many things on this form and > trying to save both the models data using one form in a single instance. I > did try the commit=False method too but it gave an error which i couldnt > figure out. Everytime i try doing something new an unknown error/exception > pops up that too in some random file and location :(. > > No, really, code does not behave this way. Errors do not pop up randomly in random locations. You need to learn how to interpret the debug information the system is providing you. > This is the traceback which i got now after changing code > > Environment: > > > Request Method: POST > Request URL: http://127.0.0.1:8000/cd/registration/register/ > > Django Version: 1.3 > [snip] > Traceback: > File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in > get_response > 111. response = callback(request, *callback_args, > **callback_kwargs) > File "C:\Users\pradeep\Desktop\cd\registration\views.py" in register > 23. return direct_to_template('success.html',{}) > File "C:\Python27\lib\site-packages\django\views\generic\simple.py" in > direct_to_template > 26. c = RequestContext(request, dictionary) > File "C:\Python27\lib\site-packages\django\template\context.py" in __init__ > 177. self.update(processor(request)) > File "C:\Python27\lib\site-packages\django\core\context_processors.py" in > debug > 53. if settings.DEBUG and request.META.get('REMOTE_ADDR') in > settings.INTERNAL_IPS: > > Exception Type: AttributeError at /cd/registration/register/ > Exception Value: 'str' object has no attribute 'META' > > While the ultimate error here appears to be in Django code, line 23 of your views.py file is higher up in the traceback, and that is the line causing the problem. You are not passing the correct parameters to direct_to_template. I'm not going to lay out what the correct parameters should be (you could work that out for yourself by reading the docs), because you shouldn't really be using direct_to_template there. The common pattern for processing forms in a view is laid out here: https://docs.djangoproject.com/en/1.3/topics/forms/#using-a-form-in-a-view (Looking at that example I notice it should be updated to use render, not render_to_response, but the overall pattern for the view is still correct. Note that in the case of successful POST processing, the code in that view returns a redirect, not a regular response. This is a general web application pattern, not specific to Django, you can read about the reasons for it here for example: http://en.wikipedia.org/wiki/Post/Redirect/Get ) Besides not redirecting after a successful completion, you are using two different templates for different flows through your view, which is also probably not what you want. You are using register.html for the initial get of the page, and regcheck1.html for the case where the posted forms don't validate successfully. In general you should be using the same template for these cases. Karen -- http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.