ImportError when using heroku for my django web - django

I checked django is installed properly and in my 'requirements.txt' I wrote 'Django==3.2.3'. However, I cannot use this code:
heroku run python manage.py migrate
So I checked this code:
python manage.py migrate
and found out it worked properly. I know that there are existing questions and read many of them, but I think I have tried everything I could do. I would be really grateful if someone can solve this problem.

your question isn't clear tbh.
install all the dependencies by using the pip freeze command and try to run your heroku commands in the heroku bash available in your heroku dashboard
to run the commands on your heroku machine from your CMD, then command is
heroku run bash --app your_app_name
then you can run whatever command you want.
but I am not sure what is the exact problem you are having.

Related

Django-crontab is not working on in linux ec2 instance

I'm trying to set up cron jobs in my django application on a ec2 instance(linux). Everything is working fine, I tried
python3 manage.py cron add
python3 manage.py cron show
python3 manage.py cron remove
everything works just fine
But when I start the apache server, and load the page, I'm getting 500. From the error logs I found that django_crontab module was not found. But it's still there and I've installed it in the virtual environment too (I've double checked with pip3 freeze). I also tried sudo service cron start which didn't show me anything and didn't make any difference. What could be the possible issue here?
Atleast I found the answer myslef. Freezing the pip3 modules and installing it in the server environment solved my issue. MODULE_IMPORT ERROR can be rectified by this method even if your module is not visible when installed manualy using pip3 install module-name. I hope this works for others!

Error in makemigrations and migrate in pycharm using django

Guy i was working on a django website i create a django website before also but this time when ever i run command
Python manage.py makemigrations
Its stop there no error nothing shows after this command
Suggest me what to do
And one thing i run the python makemigration blog
(Blog is app name here)
Its is working properly then but after this migrate command will hang
Detail : I created a project name blogs
And inside it i create a app blog
I am using postgresql database
After writing model class
I run the make migration command
And it shows nothing and no other command i can write after this as shown in image enter image description here
virtual environment using pipenv (follow below commands)
pipenv install django==3.0.1
then start the virtual enviorment
pipenv shell
then run your migrations command

django pycharm error : Process finished with exit code 1

I'm new to web programming. I'm sorry if the question is ridiculous. A few days ago I put my code in the git branch, today I downloaded it from the directory I received using the git clone <git repo url> on my laptop. I've built ENV and installed this requirement. But whenever I run python manage.py runserver, I saw the error below:
Process finished with exit code 1
for more information : makemigrations and migrate works correctly.
How can I fix the problem? Thanks in advance for your guidance
You have to run two commands before running the server .These are:
python manage.py makemigrations
and
python manage.py migrate
These will create the database

Python manage.py startapp does not work

When I run the python manage.py startapp "app name" command in my Django project directory nothing happens... Every other manage.py command works without problem.
What could be the problem?
Thanks a lot!!
Andrew
The first line in manage.py breaks the file on windows. The first line should look like this:
#!/usr/bin/env python
Removing it fixes the issue for me. Please try this is really helpful. Thanks
This problem occurs due to Python Path is not set, you can reinstall python and check the box that says "Add to Path 3.9"
Are you running the correct version of Python and correct version of Django?
To check Django:
python manage.py --version
Make sure you are running the right versions, if you are have Python 3 and Python 2 installed you may have multiple versions of Django.
Try to set environment variables on the command line? This path is if you were using vagrant.
PYTHONPATH=/vagrant/www DJANGO_SETTINGS_MODULE=settings django-admin.py startapp
Then try manage.py does it work? Without setting envs on the command line?
Adding a virtual environment is necessary to get the above command working. In the virtual environment you can specifically install Django and it is done so as to ensure that no other package interfers with the Django framework. I was also facing the same issue but after creating a virtual environment, things became super easy!!!
I would recommend using pycharm as creating a virtual environment is just as easy as running a hello world program!!. Also paste the following code at the settings.py script at the end :
ALLOWED_HOSTS=['*']
Also specify the correct directory while running in the terminal. Be sure to check that the code should be written inside the project directory.
Hope that helps :)
I was facing a similar issue and saw this question. Tried the methods mentioned by some of the users but it did not work. Surprisingly the only thing I had to do was remove the word "python" from the command. All I typed in the command line was - manage.py startapp "appname"
I have no idea what difference does it make or how I made it work, but if anyone has a similar problem I hope your issue gets resolved.
I think it maybe because i had previously added the directory I am working in the PATH variable. Not sure. Someone has an opinion on this, do share.
I think i may have found the solution. If you're running on python 3.7 or above, try setting your directory to ~\YourProjectName\YourProjectName with the cd commmand then type py -m django startapp <appName>
The command
$ python-admin startapp main
returns the error " bash: python-admin: command not found".
I was able to resolve using the following command instead
$ py -m django startapp main
if some of you are following old tutorials on django then after you have python version 3.7 or above then the command "python manage.py startapp 'appname'" doesnt works.//well it didn't work for me so insted of that command you can use "py -m django startapp 'appname'"
it worked for me so you can also try that..
the command -> manage.py startapp 'appname'" works for python version upto 3.7 and for 3.7 and above version used command -> "py -m django startapp 'appname'" it works for me...

Django Buildout to Virtualenv

beginner Django developer here.
I started a personale project with buildout and now I wanted to test some deploying, I decided to go with heroku, but I immediately noticed that heroku works with virtualenv and a requirements.txt file. My question is, is there a way to deploy a buildout project to heroku or convert said project to use virtualenv? If yes, how can I achieve this?
Thanks
Buildout and virtualenv can work just fine together.
Upload your buildout.cfg, your bootstrap.py and use the virtualenv python to run the bootstrap.py script.
Kenneth Reitz (of requests fame, and Heroku's Python guy) has created a buildpack that does just that.