httpresponse from stand alone script

2012-08-24 Thread Blaxton
Hi

I am calling a stand alone script from within views.py and 
was able to generate a html 
file with render_to_string in a stand alone script
by include followng line:
from django.template.loader 
import render_to_string

now , need to use "httpresponse" to generate a response.
is it possible ? tried importing httpresponse and then use
"return httpresponse" but got error from "return" as it is a stand alone
script and not a funtion. 


currently, I am writing the result of stand alone script to a file and then 
render it
in views.py.

If I could pass some variables to views.py , or if I could use httpresponse in
stand alone script , then there was no need of writing to a file and then 

render the file.

Thanks for help

-- 
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.



Re: invoking a funcion or module as root

2012-08-18 Thread Blaxton
Thank you Jirka,
Changed the function to stand alone script and called it with sudo from 
views.py.
that worked and solved my problem.







 From: Jirka Vejrazka 
To: django-users@googlegroups.com 
Sent: Tuesday, August 14, 2012 1:03:29 PM
Subject: Re: invoking a funcion or module as root
 
Hi there,

   you definitely don't want to allow apache to setuid() to root as
you've pointed out. You have a few options, probably the easiest one
is to write a pair of scripts for each task you want your application
to perform with root privileges.

  - the first script will only contain "sudo "
  - the second script should contain the necessary step(s) that need
to be performed with root privileges. It should be simple to minimize
chances for security issues

  Then you'd configure your sudoers file to allow apache process to
call the "second script" *including the right set of parameters* (if
applicable) with sudo permissions.

  You'd then call your "first script" using subprocess() call from
your views.py (or whereever appropriate).

  (you could technically bypass the whole "first script", but it'll
greatly improve readability if you do it this way, no one will have to
read your python code to match it to your sudoers file if problems
occur).

  Even better solution would be fixing your security model, having a
web application perform high-privileged tasks on a system seems flawed
in 99% of cases I can think of, but maybe you have a good reason why
you need it that way.

  HTH

    Jirka

-- 
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.

-- 
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.



invoking a funcion or module as root

2012-08-14 Thread Blaxton
Hi

I have setup Django with wsgi and Apache on Linux and all is good,
but the application that I am building should be able to modify
Linux files which are only allowed by root.

so, I have created a function named myfunc in a module named mymodule.py
and has invoked the function in my application's views.py.

now , How can i invoke mymodule.py as root, or is there any way to invoke
only myfunc as root ?

I already setup sudo , and was able to create directory as root with mkdir 
command
but what about python methods such as open(), how can I open( ) a file as root 

while funciton is being invoked as apache user ? tried adding mymodule.py and 
python
to a list of commands in suduers file , but still there is a problem with 
creating the file. 


even , os.setuid() won't work, because function is being invoked as apache user.

thought about setting setuid on python executable, but setuid is not working on 
scripts and have to write
a program in C or C++ and make it setuid and then invoke it through Django and 
python
but don't want to go that way to keep every thing in Python language.

the main question is "how to invoke a python function or module as root from 
view"
but I am open for any better solution.

Thanks

-- 
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.



Re: named url patterns - invalid syntax

2012-08-06 Thread Blaxton
Thank you for your help

I just learnt about the url funciton but went with 

(r'^myform/$', 'mysite.views.myform', {}, 'myform')

as it would be the same as other patterns in urls.py

Thanks again





 From: Alexis Roda 
To: django-users@googlegroups.com 
Sent: Sunday, August 5, 2012 4:51:46 PM
Subject: Re: named url patterns - invalid syntax
 
Al 05/08/12 13:43, En/na Blaxton ha escrit:
> 
> Hi
> 
> Why following line cause an invalid syntax :
> (r'^myform/$', 'mysite.views.myform', name="myform"),

Because it's syntax is invalid: the 'name=value' is allowed in function calls 
but not in tuples.

Try with:

urlpatterns = patterns('',
    url(r'^myform/$', 'mysite.views.myform', name="myform"),
    ...
)

> it seems named url pattern has changed from name="myform" to just 'myform'
> because when I change it to:
> (r'^myform/$', 'mysite.views.myform', 'myform'),
> 
> it pass the syntax error and throw another error :
> 
> dictionary update sequence element #0 has length 1; 2 is required

When you use a tuple the syntax is:

(regular expression, Python callback function [, optional dictionary [, 
optional name]])

the third element, if present, is expected to be a dictionary. Try with:

(r'^myform/$', 'mysite.views.myform', {}, 'myform')




HTH

-- 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.

-- 
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.



named url patterns - invalid syntax

2012-08-05 Thread Blaxton


Hi

Why following line cause an invalid syntax :
(r'^myform/$',  'mysite.views.myform', name="myform"),

it seems named url pattern has changed from name="myform" to just 'myform'
because when I change it to: 

(r'^myform/$',  'mysite.views.myform', 'myform'),

it pass the syntax error and throw another error :
dictionary update sequence element #0 has length 1; 2 is required

I am following this document:
 https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs

to link a page to another one but it is not working.


Thanks

-- 
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.



Login Required Middleware

2012-07-30 Thread Blaxton
Hi

I am trying to use login required middleware in a project
and followed every step mentioned on following url ,
but its just not working.

http://djangosnippets.org/snippets/1179/

placed the above middleware in myproject/middleware.py

added following lines to settings.py
LOGIN_URL = '/'
MIDDLEWARE_CLASSES = (

'myproject.middleware.LoginRequiredMiddleware'
)

django.core.context_processors.auth is changed to
django.contrib.auth.context_processors.auth

and it is in global_settings.py.

but still it wont forward the anonymouse users to login page which is '/'

Thanks

-- 
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.



Re: Prevent direct access to some URLs

2012-07-26 Thread Blaxton
I just figured the solution is using @login_required decorator.

Thanks




 From: Blaxton 
To: "django-users@googlegroups.com"  
Sent: Wednesday, July 25, 2012 10:42:31 PM
Subject: Prevent direct access to some URLs
 

Hi
I have set up a login page, using "django.contrib.auth.views.login"
and user's would be forwarded to  their own web page after being 
authenticated, but they can access to their web page directly with 
placing the related uri.

 how can I prevent direct access to those page ?


Thanks


-- 
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.

-- 
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.



Prevent direct access to some URLs

2012-07-25 Thread Blaxton
Hi
I have set up a login page, using "django.contrib.auth.views.login"
and user's would be forwarded to  their own web page after being 
authenticated, but they can access to their web page directly with 
placing the related uri.

 how can I prevent direct access to those page ?


Thanks

-- 
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.



Re: Writing or editing files using Django

2012-06-19 Thread Blaxton
My understanding from template system was:
Django template system is to create html files on fly while returning
the resulting html to user's browser  and the resulting static files
would not be saved any where in file system.

How can I save the created files by template system on file system ?






 From: kenneth gonsalves 
To: django-users@googlegroups.com 
Sent: Tuesday, June 19, 2012 3:42:34 PM
Subject: Re: Writing or editing files using Django
 
On Tue, 2012-06-19 at 00:40 -0700, Blaxton wrote:
> I am a newbie in Django and in need of some hints to 
> point in the right direction. 
> 
> I am building a new 
> application which users would enter some names and then 
> after 
> clicking on submit, some non .html files should be created or
> modified 
> while entered data should be inserted in some parts of the file that 
> have been created 
> or modified. also those files are not going to be
>  served in web, they are just 
> some static files located at 
> different locations in system for other uses. 

why use django? just plain html using cheetah or mako or jinja and some
python will do the trick.
> 
> should I start using template  to generate those non html files ? 
> does Django has
>  a module to create a file and capable of insert parameters to file ? 
> which python template is best suited and supported by Django ? jinja2 
> or mako or cheetah ? 

the django template language is best suited and supported by django - of
course you are free to use anything you want.
> 
> what is the best way of calling C++ 
> programs within Django ? 

subprocess.call()?
-- 
regards
Kenneth Gonsalves

-- 
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.

-- 
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.



Writing or editing files using Django

2012-06-19 Thread Blaxton
I am a newbie in Django and in need of some hints to 
point in the right direction. 

I am building a new 
application which users would enter some names and then 
after 
clicking on submit, some non .html files should be created or modified 
while entered data should be inserted in some parts of the file that 
have been created 
or modified. also those files are not going to be
 served in web, they are just 
some static files located at 
different locations in system for other uses. 

should I start using template  to generate those non html files ? 
does Django has
 a module to create a file and capable of insert parameters to file ? 
which python template is best suited and supported by Django ? jinja2 
or mako or cheetah ? 

what is the best way of calling C++ 
programs within Django ? 

-- 
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.



Writing or editing files using Django

2012-06-19 Thread Blaxton
I am a newbie in Django and in need of some hints to point in the right 
direction.

I am building a new application which users would enter some names and then
after clicking on submit, some non .html files should be created or modified
while entered data should be inserted in some parts of the file that have been 
created
or modified. also those files are not going to be served in web, they are just
some static files located at different locations in system for other uses.


should I start using template  to generate those non html files ?
does Django has a module to create a file and capable of insert parameters to 
file ?
which python template is best suited and supported by Django ? jinja2 or mako 
or cheetah ?

what is the best way of calling C++ programs within Django ?

-- 
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.