python - How to create a Django project by running a shell script/command from another Django project -


files structure:

project_one │   manage.py │   shell_script.py   │ └───project_one │      settings.py │      urls.py │      views.py │      .... │                 └───templates       login.html       loggedin.html       ...   ``` 

loggedin.html

 ... <form action="/submit" method = "post">    {% csrf_token %}    <label for="db">data base name:</label>       <input type="text" name="db" id = "db"><br>   <label for="username">user name:</label>       <input type="text" name="username" id = "username"><br>   <label for="password">password:</label>       <input type="password" name="password" id = "password"><br>   <input type="submit" value="submit"> </form> ... 

after clicking submit button redirecting urls.py, upto working fine.

urls.py

 ...  urlpatterns = [      ...      url(r'^submit', views.submit, name='submit'),      ...  ] 

views.py

  ...   import subprocess    def submit(request):         db = request.post['db']        username = request.post['username']        password = request.post['password']         # after clicking submit button loggedin.html , trying run "shell_script.py" has django commands , scripts         subprocess.call('python3 path_to_project_one_directory/shell_script.py', shell=true)        return render_to_response('submit.html',                  {'db': db,                   'username':username,                  'password':password                 })         ... 

shell_script.py

import subprocess  subprocess.call('django-admin startproject project_two',shell=true) subprocess.call('python3 path_to_project_two.py/manage.py inspectdb > path_to_project_two.py/models.py', shell=true) # other shell commands ... 

after running project_one , after login , entering form information in "loggedin.html" when click submit button "shell_script.py" should run according me showing errors.

  traceback (most recent call last):   file "/usr/bin/django-admin", line 5, in <module>   management.execute_from_command_line()   file "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in        execute_from_command_line  utility.execute()  file "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute settings.installed_apps  file "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__ self._setup(name) file "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup self._wrapped = settings(settings_module) file "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__ mod = importlib.import_module(self.settings_module) file "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) importerror: no module named project_one.settings  [06/apr/2017 06:57:57] "post /submit http/1.1" 200 159  traceback (most recent call last):  file "/usr/bin/django-admin", line 5, in <module>  management.execute_from_command_line() file "/usr/lib/python2.7/site-     packages/django/core/management/__init__.py", line 353, in   execute_from_command_line  utility.execute() file "/usr/lib/python2.7/site- packages/django/core/management/__init__.py", line 302, in execute settings.installed_apps file "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__ self._setup(name) file "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup self._wrapped = settings(settings_module) file "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__ mod = importlib.import_module(self.settings_module) file "/usr/lib64/python2.7/importlib/__init__.py", line 37, in  import_module  __import__(name) importerror: no module named project_one.settings [06/apr/2017 07:01:31] "post /submit http/1.1" 200 159 

while when run "shell_script.py" seperately running when call "shell_script.py" "views.py" showing above errors.

any appreciated, if else want ask please feel free ask.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -