0

I want to create a Django app from user input. Here is my code.


def createAppname(name):
    split_name = name.split(" ")
    
    s = "".join(i[0:] for i in split_name)
    return s

def formFields(request):
    if request.method == 'POST':
        app_name =  request.POST.get('app')

        new_name=createAppname(app_name)

        from django.core.management import call_command
        call_command('startapp', new_name)

        return render(request,'forms_new.html')

    return render(request, 'forms_new.html')

The code works perfectly when I am executing in the development environment. But after deploying on the production server, here I'm using apache_mod_wsgi, I get the following error.



Traceback (most recent call last):
  File "/path/to/env/lib/python3.6/site-packages/django/core/management/templates.py", line 70, in handle
    os.makedirs(top_dir)
  File "/path/to/env/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)

During handling of the above exception ([Errno 13] Permission denied: '/thisisnewappfromServer'), another exception occurred:
  File "path/to/env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/path/to/env/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/rohit/Documents/Web_app/project/new_models/views.py", line 70, in formFields
    call_command('startapp', new_name)
  File "/path/to/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 168, in call_command
    return command.execute(*args, **defaults)
  File "/path/to/env/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/path/to/env/lib/python3.6/site-packages/django/core/management/commands/startapp.py", line 14, in handle
    super().handle('app', app_name, target, **options)
  File "/path/to/env/lib/python3.6/site-packages/django/core/management/templates.py", line 74, in handle
    raise CommandError(e)

Exception Type: CommandError at /models/details/
Exception Value: [Errno 13] Permission denied: '/thisisnewappfromServer'

Please help me out here. Thanks.

2
  • Why do this? What code will these apps have then? It is generally better to make your code handle everything itself rather than dynamically having it create more code to handle stuff. Commented Jul 2, 2021 at 7:15
  • I'm trying to create a project where a user can create an app dynamically and also the files inside it. Commented Jul 3, 2021 at 7:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.