django: I accidentally deleted the manage.py file. how to recover it? - django

I accidentally deleted the manage.py file with vim nerdtree. apparently, there isn't a way to recover it I I don't know what to do.
can I somehow create a new one or restore it?

You can easily copy this file by changing the "start.settings" with your "application.settings". The other codes is always the same :)
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'starter.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

You can create a new Django project by using the following command:
django-admin startproject someappname
and copy the file into your project and ensure to change the app name on the manage.py file

Related

django runserver command is not starting the server

I'm running Django and I can't figure out why it's coming out like that.
It turns out that Python and Django are installed.
input : python manage.py runserver
output : Python
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cmapsite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
Did you activate your Virtual Environment in CMD terminal ?
If No then First Activate your Virtual Environment, It may be a reason of not starting Server.
If you already created the virtual environment then which is the error that you keep getting ? Upload the Error.

SyntaxError: invalid syntax manage.py except ImportError as exc:

I have created a django project called tictoctoe
but when I run "py manage.py runserver" it gives me following error.
File "manage.py", line 11
except ImportError as exc:
^
SyntaxError: invalid syntax
it used to work fine earlier.
here is
manage.py
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tictactoe.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
Please make sure your virtual environment is activated where you have Django installed.
I could figure out what was wrong,
I have created project directory inside the virtual environment, hence without activating the virtual environment it gives that error.
after I activating venv, py manage.py runserver works fine.
How to activate virtual environment:
my project location:
c:\Users\xyz\Documents\django-projects
my virtual environment location is
c:\Users\xyz\Documents\django-projects\django-env
go to
c:\Users\310227436\Documents\django-projects\django-env\Scripts
invoke activate:
c:\Users\310227436\Documents\django-projects\django-env\Scripts> Activate
after doing this problem should be resolved.

error with django.core.exceptions.ImproperlyConfigured: on Django 2.2.5

I know that this question has been asked before and I went through every possible answers given, and it still does not make it for me! I am running django 2.2.5 and python 3.7 on PyCharm.
My manage.py seems to be working fine. The issue is coming from my admin file, I believe I know but I do not know where the issue could be. I ran django-admin check in terminal, which also give me an error. My only file that raises an error is my admin.py, but I cannot understand why. I copied my admin.py file as well as the errors that I get when I write the commands on the terminal
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from inventory1.templates.models import *
#admin.register(Item)
class ViewAdmin(ImportExportModelAdmin):
exclude= ('id',)
And when I execute it, I get the error:
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Now, I am sure this is related too. When I try django-admin check, I get:
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but settings are not configured.
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
From previous questions, this issue was coming from an issue with settings in the manage.py file. I am confident that this one is correct, I still add it just in case:
import os
import sys
if __name__ == '__main__':
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "inventory_management.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

manage.py file showing invalid syntax error

My application was running fine when I was running it on my local machine. But, as soon as I uploaded it on a server , manage.py is giving the following error -
File "manage.py", line 14
) from exc
^
SyntaxError: invalid syntax
This is the code for manage.py -
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "chatbot.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc ***//Here is the error***
execute_from_command_line(sys.argv)
I am using Python 2.7 and Django 1.11
kindly refer this link: How to solve SyntaxError on autogenerated manage.py?
What I have learned from the above link is that if we have two versions of python, then we need to specify the version in which we need to run our application like below:
python3 manage.py runserver

Getting a syntax error on a system generated file while working with django! How to fix it?

While I am setting up a supeuser in my django project using the command
$ python manage.py syncdb
File "manage.py", line 14
) from exc
^
SyntaxError: invalid syntax
manage.py is a system generated file still it shows a syntax error.
Here is the manage.py file! -
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"my_django15_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Please tell some solution!
The from part of raise is not supported in Python 2.x. Use Python 3.x instead.