1

I have this following method to create project as below.

import os
project_directory = "/Users/home/project_directory/"

def create_function(project_name):
    os.system("django-admin.py startproject {0} {1}".format(
            project_name,
            project_directory
        )
    )

This works well when I use global python shell, But when I try same command using python manage.py shell I encounter following error. I thinking I am messing with python path, Please help me out

 mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
    ImportError: No module named mysite.settings
Amar
  • 666
  • 5
  • 13
  • 3
    Are you trying to create a new project using _another_ project's `manage.py`? – Selcuk Mar 10 '16 at 12:33
  • Yes. One of my view uses this function to create new project. – Amar Mar 10 '16 at 12:35
  • 2
    You have a view in one Django app that automatically creates a new Django project? This sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. Please make sure to ask about what you are trying to accomplish, not what you think the solution is. – ChrisGPT was on strike Mar 10 '16 at 12:44
  • @Chris sorry for confusing! Yes i want my django project to start another project – Amar Mar 10 '16 at 12:48
  • Answer for Y problem: You need to set `DJANGO_SETTINGS_MODULE` for manage.py to run correctly. Double check `os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")` section in Your manage.py. Changing this environment variable may interfere with Your running python script badly though. – Konstanty Karagiorgis Mar 10 '16 at 12:52
  • 1
    @Amar, what I mean is _why_ do you want to do this? I suspect there's a better solution to whatever problem you are trying to solve by doing this. – ChrisGPT was on strike Mar 10 '16 at 12:57
  • @Chris I m not sure how do i do it? Can you suggest me some options. – Amar Mar 10 '16 at 13:01
  • @Amar , Chris is asking **why** you want to do this, not **how**. *Why* do you want to do this? – rnevius Mar 10 '16 at 13:13
  • Oh ok! I have some people to whom i want to create interface and let them add projects and create simple apps , without them having to code. – Amar Mar 10 '16 at 14:19

0 Answers0