[Django] how to debug when I send the data by POST.

2013-03-11 Thread lx
*hi: *
*   I'm a new one in django, I' using the django recevice the data by POST.*

*for examle:*

wget -v --post-file=conf.xml http://192.168.23.21:8001/time/


*this way can't show the wrong message, when I write the wrong code like
this:*

 conf_xml =  request.body
 root = ET.fromstring(conf_xml)
 root = tree.getroot()

*the wrong messages is:*
*
*
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/wsgiref/handlers.py", line 86, in run
self.finish_response()
  File "/usr/local/lib/python2.7/wsgiref/handlers.py", line 127, in
finish_response
self.write(data)
  File "/usr/local/lib/python2.7/wsgiref/handlers.py", line 215, in write
self._write(data)
  File "/usr/local/lib/python2.7/socket.py", line 322, in write
self.flush()
  File "/usr/local/lib/python2.7/socket.py", line 301, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 104] Connection reset by peer

Exception happened during processing of request from ('192.168.23.21',
47107)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/SocketServer.py", line 582, in
process_request_thread
self.finish_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 323, in
finish_request
self.RequestHandlerClass(request, client_address, self)
  File
"/usr/local/lib/python2.7/site-packages/django/core/servers/basehttp.py",
line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/SocketServer.py", line 641, in __init__
self.finish()
  File "/usr/local/lib/python2.7/SocketServer.py", line 694, in finish
self.wfile.flush()
  File "/usr/local/lib/python2.7/socket.py", line 301, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe


*the question is how to debug easily except  Web Page.*
*
*
*thank you.*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




How to get the the filename of WGET?

2013-03-29 Thread lx
hi all:
I want to send information to django use this:
wget -v --post-file=conf.xml http://192.168.23.73:8001/ipdb_file/

And the Python code is:

def receive(request):
"""
receive all the xml form myCONF.
"""
if request.method == 'POST':
conf_xml =  request.body
result = handle_xml(conf_xml)
else:
result = "42"

html = "It is now %s." % result

return HttpResponse(html)



I want to know how to get the filename in the WGET like conf.xml

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




How to change the {{ form.as_table }}

2013-04-07 Thread lx
hi, I'm using the forms,and* the code is:*

from django import forms
class dcForm(forms.Form):
"""
"""
TOPIC_CHOICES = ( ('cnccdn', 'cnccdn.com'), ('lxcdns', 'lxcdns.com'),
('wscdns', 'wscdns.com'),)
dnssystem = forms.ChoiceField(choices=TOPIC_CHOICES)
dn = forms.CharField()
cv = forms.CharField()

*the template is:*



{{ form.as_table }}



the WEB is:
[image: 内嵌图片 1]

*I want to replace the "Dnssystem, Dn, Cv" to "dnssystem, dn, cv".*
How to solve it?
Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<<未命名.jpg>>

What's wrong with the Basic configuration of apache and mod_python?

2013-05-09 Thread lx
hi:
  the the Basic configuration of apache is:

LoadModule python_module /usr/lib64/httpd/modules/mod_python.so

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug On
PythonPath "['/var/www/html',
'/usr/local/gdnsplus_conf/www/mysite'] + sys.path"


I have done:
ln -sf /usr/local/gdnsplus_conf/www/mysite /var/www/html/gdnsplus_conf

the version of django is:1.4.5
the version of mod_python is:3.3.1
the directory of of django app is:  /usr/local/gdnsplus_conf/www/mysite
the context of app is:
ll /usr/local/gdnsplus_conf/www/mysite
total 184
-rw-r--r-- 1 apache root  2970 Mar 25 16:20 conf.xml
-rw-r--r-- 1 apache root  4992 Apr 25 17:15 cv
-rw-r--r-- 1 apache root  4991 Apr 25 17:16 cv_all
-rw-r--r-- 1 apache root  6727 Mar 29 18:05 hand_xml.py
-rw-r--r-- 1 apache root 0 Mar 12 09:12 __init__.py
-rw-r--r-- 1 apache root   134 Mar 12 09:15 __init__.pyc
-rw-r--r-- 1 apache root  5720 Apr 17 15:27 settings.py
-rw-r--r-- 1 apache root  5400 Mar 12 09:33 settings.py.bk
-rw-r--r-- 1 apache root  3118 Apr 17 15:27 settings.pyc
-rw-r--r-- 1 apache root  2080 Apr 22 13:34 tags
drwxr-xr-x 2 apache root  4096 May  9 13:46 templates
-rw-r--r-- 1 apache root62 Apr 27 11:05 test
-rw-r--r-- 1 apache root  1238 May  9 11:09 urls.py
-rw-r--r-- 1 apache root  1144 May  9 11:10 urls.pyc
-rw-r--r-- 1 apache root 34352 May  9 13:45 views.py
-rw-r--r-- 1 apache root 30384 Apr 16 09:06 views.py.bk
-rw-r--r-- 1 apache root 33425 May  9 14:55 views.pyc
-rw-r--r-- 1 apache root  1134 Mar 12 09:12 wsgi.py
-rw-r--r-- 1 apache root  1028 Mar 12 09:15 wsgi.pyc

the infomation of  urls.py is:
urlpatterns = patterns('',
(r'^conf_xml/$', receive),
(r'^dc_list/$', listall),
(r'^show_err/$', show_err),
(r'^ipdb_file/$', ipdb_file),
(r'^ipdb_update/$', ipdb_update),
(r'^task_list/$', task_list),
(r'^task_search/$', task_search),
(r'^nip_set/$', nip_set),
(r'^nip_del/$', nip_del),
(r'^nip_update/$', nip_update),
(r'^ns_set/$', ns_set),
(r'^ns_list/$', ns_list),
(r'^reversion_list/$', list_version),
(r'^version_set/$', version_set),
(r'^index/$', all_err),
(r'^machine/$', show_machine),

The question is:
http://192.168.23.73/ns_list
is not work.

How to solve it ? thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: What's wrong with the Basic configuration of apache and mod_python?

2013-05-10 Thread lx
I have choiced to use the wsgi.

2013/5/10 lx 

> hi:
>   the the Basic configuration of apache is:
>
> LoadModule python_module /usr/lib64/httpd/modules/mod_python.so
> 
> SetHandler python-program
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE mysite.settings
> PythonOption django.root /mysite
> PythonDebug On
> PythonPath "['/var/www/html',
> '/usr/local/gdnsplus_conf/www/mysite'] + sys.path"
> 
>
> I have done:
> ln -sf /usr/local/gdnsplus_conf/www/mysite /var/www/html/gdnsplus_conf
>
> the version of django is:1.4.5
> the version of mod_python is:3.3.1
> the directory of of django app is:  /usr/local/gdnsplus_conf/www/mysite
> the context of app is:
> ll /usr/local/gdnsplus_conf/www/mysite
> total 184
> -rw-r--r-- 1 apache root  2970 Mar 25 16:20 conf.xml
> -rw-r--r-- 1 apache root  4992 Apr 25 17:15 cv
> -rw-r--r-- 1 apache root  4991 Apr 25 17:16 cv_all
> -rw-r--r-- 1 apache root  6727 Mar 29 18:05 hand_xml.py
> -rw-r--r-- 1 apache root 0 Mar 12 09:12 __init__.py
> -rw-r--r-- 1 apache root   134 Mar 12 09:15 __init__.pyc
> -rw-r--r-- 1 apache root  5720 Apr 17 15:27 settings.py
> -rw-r--r-- 1 apache root  5400 Mar 12 09:33 settings.py.bk
> -rw-r--r-- 1 apache root  3118 Apr 17 15:27 settings.pyc
> -rw-r--r-- 1 apache root  2080 Apr 22 13:34 tags
> drwxr-xr-x 2 apache root  4096 May  9 13:46 templates
> -rw-r--r-- 1 apache root62 Apr 27 11:05 test
> -rw-r--r-- 1 apache root  1238 May  9 11:09 urls.py
> -rw-r--r-- 1 apache root  1144 May  9 11:10 urls.pyc
> -rw-r--r-- 1 apache root 34352 May  9 13:45 views.py
> -rw-r--r-- 1 apache root 30384 Apr 16 09:06 views.py.bk
> -rw-r--r-- 1 apache root 33425 May  9 14:55 views.pyc
> -rw-r--r-- 1 apache root  1134 Mar 12 09:12 wsgi.py
> -rw-r--r-- 1 apache root  1028 Mar 12 09:15 wsgi.pyc
>
> the infomation of  urls.py is:
> urlpatterns = patterns('',
> (r'^conf_xml/$', receive),
> (r'^dc_list/$', listall),
> (r'^show_err/$', show_err),
> (r'^ipdb_file/$', ipdb_file),
> (r'^ipdb_update/$', ipdb_update),
> (r'^task_list/$', task_list),
> (r'^task_search/$', task_search),
> (r'^nip_set/$', nip_set),
> (r'^nip_del/$', nip_del),
> (r'^nip_update/$', nip_update),
> (r'^ns_set/$', ns_set),
> (r'^ns_list/$', ns_list),
> (r'^reversion_list/$', list_version),
> (r'^version_set/$', version_set),
> (r'^index/$', all_err),
> (r'^machine/$', show_machine),
>
> The question is:
> http://192.168.23.73/ns_list
> is not work.
>
> How to solve it ? thank you.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




hi [django-users] How to do something after "return HttpResponse(html)"?

2013-06-25 Thread lx
hi all:
  I want to do someing after "return HttpResponse(html)".
for example
""
from django.http import HttpResponse
import datetime
def current_datetime(request):
  now = datetime.datetime.now()
  html = "It is now %s." % now
  return HttpResponse(html)
"

Actually, I have a question that I need first give a response to the
client, second I do something else.
How to solve this?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: hi [django-users] How to do something after "return HttpResponse(html)"?

2013-06-25 Thread lx
Thank you.

The real demand is:

1.
receive the xml file from client.

2.
if (the xml format is ERROR) == True:
return HttpResponse(ERROR FORMAT")
else:
return HttpResponse(RIGHT FORMAT")
#I must give a response first, And do other thing. Because the spend
time of do_something() may be long.
do_something(the xml file)






2013/6/25 Sandro Dutra 

> The question is: What you're trying to do?
>
> 1. You can do any other process before the return line, the return will be
> the same... for example:
>
> from django.http import HttpResponse
> from datetime import datetime
> def current_datetime(request):
>   now = datetime.now()
>   html = "It is now %s." % now
>   year = now.year()
>   return HttpResponse(html)
>
>
> 2. You can use a conditional to have multiple returns:
> from django.http import HttpResponse
> from datetime import datetime
> def current_datetime(request):
>   now = datetime.now()
>   html = "It is now %s." % now
>   year = now.year()
>   if year == 2013:
>   return HttpResponse(html)
>  else:
>   return HttpResponse(Sorry it's not
> 2013.")
>
>
> 2013/6/25 Timster 
>
>> You cannot do something after the "return" line. This is Python
>> functionality. When you return, the function exits and does not process
>> anything else.
>>
>> What exactly are you trying to do? There is probably another way to
>> accomplish it.
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




hi [django-users]How to define the response?

2013-06-25 Thread lx
hi :
   I'm a new one. I want to fix a question.Like this:


from django.http import HttpResponse
import datetime
def current_datetime(request):
  now = datetime.datetime.now()
  if now == 2013:
  html = "It is now %s."
% now
  return HttpResponse(html)
  else:
 # giva a response first
 urllib.urlopen(message)
 # do something
 print 'not 2013'
 sys.exit(0)



How to use " urllib.urlopen(message)" instead of "HttpResponse()" ?

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: hi [django-users] How to do something after "return HttpResponse(html)"?

2013-06-25 Thread lx
Thank you.
But I want to fix it like this, because the time of "do something" is not
long.
###

from django.http import HttpResponseimport datetimedef
current_datetime(request):
  now = datetime.datetime.now()
  if now == 2013:
  html = "It is now %s." % now
  return HttpResponse(html)
  else:
 # giva a response first
 urllib.urlopen(message)
 # do something
 print 'not 2013'
 sys.exit(0)


###


2013/6/25 Hector Armando Vela Santos 

> You can use Celery for that, I've done something similar, just with a CSV
> instead of a XML, check this
> http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
>
> once installed and configured, its as simple as:
>
> from celery import task
>
> if (the xml format is ERROR) == True:
> return HttpResponse(ERROR FORMAT")
> else:
> do_something.delay(the_xml_file)
> return HttpResponse(RIGHT FORMAT")
> #I must give a response first, And do other thing. Because the spend
> time of do_something() may be long.
>
> @task(ignore_result=True)
> def do_something(xml):
> #do something time consuming
>
>
> and the do_something function will be called in second plane, and the user
> will get an instant response, even if the parsing file process takes half
> an hour
>
>
> On Tuesday, June 25, 2013 8:32:59 AM UTC-5, lx wrote:
>
>> Thank you.
>>
>> The real demand is:
>>
>> 1.
>> receive the xml file from client.
>>
>> 2.
>> if (the xml format is ERROR) == True:
>> return HttpResponse(ERROR FORMAT")
>> else:
>> return HttpResponse(RIGHT FORMAT")
>> #I must give a response first, And do other thing. Because the spend
>> time of do_something() may be long.
>> do_something(the xml file)
>>
>>
>>
>>
>>
>>
>> 2013/6/25 Sandro Dutra 
>>
>>> The question is: What you're trying to do?
>>>
>>> 1. You can do any other process before the return line, the return will
>>> be the same... for example:
>>>
>>> from django.http import HttpResponse
>>> from datetime import datetime
>>> def current_datetime(request):
>>>   now = datetime.now()
>>>   html = "It is now %s." % now
>>>   year = now.year()
>>>   return HttpResponse(html)
>>>
>>>
>>> 2. You can use a conditional to have multiple returns:
>>> from django.http import HttpResponse
>>> from datetime import datetime
>>> def current_datetime(request):
>>>   now = datetime.now()
>>>   html = "It is now %s." % now
>>>   year = now.year()
>>>   if year == 2013:
>>>   return HttpResponse(html)
>>>  else:
>>>   return HttpResponse(Sorry it's not
>>> 2013.")
>>>
>>>
>>> 2013/6/25 Timster 
>>>
>>>> You cannot do something after the "return" line. This is Python
>>>> functionality. When you return, the function exits and does not process
>>>> anything else.
>>>>
>>>> What exactly are you trying to do? There is probably another way to
>>>> accomplish it.
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users...@**googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>>
>>>> Visit this group at 
>>>> http://groups.google.com/**group/django-users<http://groups.google.com/group/django-users>
>>>> .
>>>> For more options, visit 
>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>> .
>>>>
>>>>
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, sen