I am trying to build a web interface to execute some python scripts. One such script is used to login to network devices and run some commands then saves them to an excel file.
Im unsure if this is the right way to go about it but I have made the script into a management command.
I can get the script to run from a view by using call_command() but I am stumped on how to pass the form fields as variables to the script.
Here is what I believe to be the relevant parts;
form.py
class BaseLineForm(forms.Form):
username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Required', 'size': 20}), error_messages={'required': 'Required'})
cec_pass = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Required', 'size': 20}), error_messages={'required': 'Required'})
enable_pass = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Required', 'size': 20}), error_messages={'required': 'Required'})
<additional form fields snipped...>
views.py
from baseline.forms import BaseLineForm
from django.core.management import call_command
def baseline(request):
if request.method == 'POST':
form = BaseLineForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['cec_pass']
enable = form.cleaned_data['enable_pass']
call_command('baseline')
baseline.py
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
args = ''
help = ''
def handle(self, *args, **options):
<I have tried to import the view but I get an error cannot import name views>
from baseline import views <if I run this from the shell it imports fine>
<rest of script here>
Environment; Centos 6.4, virtualenv, django 1.6, python 2.6
I am really stumped on this so thank you in advance to anyone who has any ideas to help.