There is a PyCharm Django Console.
Am I allowed to run manage.py things in that console, too?
What syntax I do enter to e.g. perform
python manage.py syncdb
in the django console?
You don't actually run it the way you're thinking. To run the manage.py tasks in PyCharm, you do the following:
On the main menu, choose Tools | Run manage.py task, or press Alt R.
In the Enter manage.py task name dialog box, start typing the desired task name. As you type, the suggestion list shrinks to show the matching tasks only.
Note that on typing an asterisk, PyCharm displays the complete list of available tasks.
Select the desired task.
Press Enter to start the task.
This was found on PyCharm's website.
Related
Inside the cpanel -> python app i have tried several time to create super user. when I tried to execute this commad inside Execute python script
manage.py createsuperuser
then it will return this error
Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.
How to solve this problem, or any manuall solution, i found several solution but all the solution for local server.
There is no difference between creating superuser on local server and production server. You have to do next:
Enter your server via ssh.
Go to your project root folder (with manage.py file)
Type python manage.py createsuperuser (use your virtual environment or system interpreter, depends on).
I am developing a Django app running on Heroku.
In order to update my database with some data coming from a certain API service, I need to periodically run a certain script (let's say myscript).
How can I use Heroku Scheduler to do it?
As already explained here, quick and simple way to answer this question is asking yourself how would you do to run that script periodically, as if you were the scheduler yourself.
Now, the best way to run a script in your Django app at any moment, it is to create a custom management command and to run it from your command prompt when you need it, like this:
python manage.py some_custom_command
Then, if you were the scheduler, you would run that command from your command prompt at every time written in the schedule.
So, a good idea would be to make Heroku Scheduler behave the same. Thus, the aim here is to have Heroku Scheduler run python manage.py some_custom_command at scheduled times.
Here is how you can do it:
In your_app directory, create a folder management and then inside it create another folder commands and finally, inside it, create a file some_custom_command.py
So, just to be clear
your_app/management/commands/some_custom_command.py
Then, inside some_custom_command.py insert:
from django.core.management.base import BaseCommand
from your_app.path_to_myscript_file import myscript
class Command(BaseCommand):
def handle(self, *args, **options):
# Put here some script to get the data from api service and store it into your models.
myscript()
Then go on Heroku > your_app > resources
In add-ons section select Heroku Scheduler, click on it so that its window opens, then click on add job, select the time you want, insert the command python manage.py some_custom_command and save.
I was wondering why my scheduled posts were not working automatically in Wagtail, but I see in the documentation that a management command is needed to make this happen. I am unfamiliar with writing custom management commands, and I am wondering how to make the python manage.py publish_scheduled_pages command fire off automatically every hour?
Where would this code go in the document tree? Is there code that I just need to drop in and it runs from there? Or is something required on the server to run these commands on a schedule?
Any help would be appreciated. I couldn't find any existing code anywhere for this functionality in Wagtail and I'm wondering why the button is in the admin to schedule a post, but the functionality is not already built in?
You are probably familiar with management commands since python manage.py runserver and makemigrations and migrate are management commands.
You can see all available commands with python manage.py -h
publish_scheduled_pages should be called periodically. Form the Wagtail docs:
This command publishes, updates or unpublishes pages that have had these actions scheduled by an editor. We recommend running this command once an hour.
Periodically executing a command can be done in various ways. Via crontab is probably the most common. To edit the crontab:
$ crontab -e
Add (for every fist minute of the hour):
0 * * * * python /path/to/your/manage.py publish_scheduled_pages --settings=your.settings
I am trying to learn how to debug a django application with PyCharm. In the application we have several custom manage.py commands. If I run there via terminal (external or Pycharm's terminal) they run fine.
If I try to run them from PyCharm (Tool -> run manage.py task) so I can debug, I get the following error:
Unknown command: 'add_question'
Type 'manage.py help' for usage.
I started working on the Django Project before using PyCharm, so I created it via django-admin, and we are adding it to pycharm as OpenDirectory->Select the project.
Any help would be helpful, be it to manage to run the command from inside PyCharm, or to connect PyCharms terminal to the debugger so that I can debug when running from PyCharms terminal.
The solution is in another answer, though a little outdated. Quick update for PyCharm 2016.3:
Run > Run... > Edit Configurations... (Note: you can add configurations by doing both "Run..." and "Debug...")
Click green + (plus sign)
In the drop down menu, choose Django Server.
Check "Custom run command" and enter your command (the part that goes after manage.py in the console.
Make sure "Port" and "Host" are empty. If not—make them empty.
Change "Name" to your liking.
"Apply" and "Close"
Now you can run this configuration (Run > Run... > Your_configuration_name) and debug it (Run > Debug... > Your_configuration_name).
You can create a configuration for a custom command you made
Select Tools->Edit Configurations.
In the left column, you will find a list and a "+" button in the upper part. Click this one, then select "Django Server.
In the right part of the same window, you check "Custom run command", and write your custom command in the box
Write a name for this configuration and select OK.
Now just run/debug, selecting the configuration you just created.
for anyone still having trouble with this. Try setting up a python run configuration which is more flexible instead of django server configuration. Checkout this post
I am trying to run
manage.py to validate models (as: manage.py validate) in the Interactive Shell of a Django project (called djangonew) using Pydev
The PYTHONPATH is set to include /djangonew ... so import djangonew and then dir(djangonew) actually gives me a name as 'settings' in the subfolder /djangonew/djangonew
but at the command-line I am unable run manage.py (and even find it)
How do I solve this issue? Thanks much
right click on project, open menu django-> custom command
and type verify ( or other command after "manage.py")