I recently made a Website based on DjangoCMS for a project I had to do in school. I also integrated a blog- app which I had made earlier in Django.
When I tried porting the project to another machine though, I get an error message saying "App 'blog/' could not be found. Is it in INSTALLED_APPS?" Also, my whole content is gone.No menus, content, pages, nothing. My DB is SQlite3
I ran the project with makemigrations blog, makemigrations website (that's what the cms-project is called) followed by runserver.
So basically my question would be: What can I do to fix this? Is there any way to make something like an identical copy of my existing project on another machine?
VirtualEnv will be good for you, i was doing the same thing, make your virtualenv relocatable with virtualenv venv_folder --relocatable, then move project folder and virtualenv folder to new server(you can use scp for transfering files over ssh).Just activate virtualenv again and runserver on your new place. >> source venv_folder/bin/activate; python manage.py runserver
Related
I am following the tutorial on plugin development at https://netbox.readthedocs.io/en/stable/plugins/development/
I have gone as far as creating the models and want to make migrations...
However, the manage.py is not found in the root of my plugin folder.
Where is it expected that manage.py is?
The manage.pyis part of the Django application (= website). It is located in the Django root folder, see e.g. Django tutorial.
So, a plugin never has got its own manage.py, but it may have got a set of migration files that are used by the Django app when python manage.py migrate is invoked and the plugin has been installed and defined as being a part of the Django app (within settings.py).
Assuming you've followed the installation instructions and installed Netbox in /opt/netbox, the manage.py file you need to use is located in /opt/netbox/netbox/ folder.
Don't forget to activate the virtual environment in /opt/netbox/venv and to set DEVELOP to True in /opt/netbox/netbox/netbox/configuration.py
Having trouble creating a Django repository on Github that everyone can use? I tried pushing the entire virtual environment at first, found out that it doesn't work like that, then I tried just pushing the Django folder, but even the manage.py is looking for a path that only exists on my PC.
How can I push the Django project, so that my group members can pull it, work on it, test it, and be able to push their changes themselves? Do we all have to be using the same virtual environment?
What was missing:
python manage.py migrate w
I tested this a couple times pushing it and pulling it from my PC and laptop.
I'm going to push the Django project onto our repository in a bit so we can start working on stuff. I'm still learning all this so this might not be entirely correct—do correct me if I'm wrong—but this worked for me. (I pushed a Django project onto my git from my laptop, cloned it onto my PC, and ran it.)
Create a folder; call it whatever you want
Install your virtual environment into this folder
I'm using venv, but all VEs should work (for venv, python -m venv .; the dot installs it in the current directory)
When you clone the repository, clone it in this same folder; or, if the repository doesn't exist yet, create it here; don't go into the folder yet
After it's cloned, activate your virtual environment
Once your VE is active, go into our repo folder (DroneWebsite)
Go into the src folder
pip install django==3.2.7
python manage.py migrate
It should be good to go! To test:
python manage.py runserver
I am a new to Django and have 0 experience with this framework.
I cloned a project from git it came with requirements.txt file, but I am not sure how to run it.
Do I need to create virtual environment first and clone the project into the directory of the virtual environment, and then install the requirements?
Do I need to clone the project first into some folder and then create the virtual environment inside this folder and then install the requirements?
Do I need to use any special IDE to run the project? I tried opening the project in PyCharm, without creating a virtual environment first, and it asked me if I want to install the requirements.
I would be glad if someone could explain what is the correct way to run an already existing project.
Let's come to your doubts one by one :
Cloning a repo has nothing to do with Django. You are just making a copy of the code on your disk. Now the copy can be kept anywhere you like(say in ~/Desktop). Also, the directory of a virtual envt. just contains the code of modules you might directly import(like Django), and has nothing to do with the code of the django project. So cloning can be done before or after activating the virtual envt.
You need not create a virtual envt., but you should. A virtual envt. just ensures that you can have different versions of the same module for your different projects. It keeps things organised. So, for example you can create two different virtual envt.'s one with Django=2.0 and another with Django=1.9, to test your website for the two different Django versions.
requirements.txt contains all the modules you will be needing to run the django application. So you first create a virtual envt, activate it and then in the virtual envt., install all the modules you will need. Generally do pip install -r requirements.txt
Now all the required modules are installed, To run the website on a local server( which Django will create for you ), do python manage.py runserver and open in the browser.
No, you don't need an IDE to run the django project. Editing the code on any text editor and running the server from terminal works just fine.
P.S: If you are completely new to python, I would recommend using the conda python distribution. You can create new virtual envt. using conda create as well.
1.Grab a copy of the project.
git clone new_project.git
2.Create a virtual environment and install dependencies.
mkvirtualenv new_project
pip install -r requirements.txt
3.Duplicate new_project/new_project/local_settings_example.py and save as local_settings.py.
4.Enter your database settings in local_settings.py.
5.Initialize your database.
python ./manage.py syncdb
python ./manage.py migrate
6.If your app has a custom user model, you'll need to create a new superuser for the admin.
python ./manage.py createsuperuser
7.Run the development server to verify everything is working.
python ./manage.py runserver
My context
I'm educating myself with Python Flask via the official tutorial.
I'm using Pycharm IDE (community edition) in Ubuntu Destkop 16.
The issue
I open the sample code of this tutorial as a Pycharm project
Got the Invalid Python interpreter error as below snapshot
My question
How can I fix it?
It's looking for a functional Python installation.
If you open the 2 drop-down you've referenced you'll see a selection of Python installations on your machine.
The better option though, is to create a virtualenv for your current project, so click on the cog icon to the right of the Project Interpreter drop-down and click Create VirtualEnv and follow the prompts.
Once created, it should pick that VirtualEnv as the default Python interpreter for that project and your error will disappear, though remember, because it's a new virtualenv, it won't yet have Flask etc installed on it. You can install the Flask library by clicking the + icon underneath the cog and searching/installing for Flask.
Alternatively, create a requirements.txt file on your project root directory, with Flask as the contents, and PyCharm will notice that next time you are in a .py file and suggest to automatically install Flask.
I'm still busy with my Django learning adventure. In another post I asked about how to structure a Django project and applications using buildout. In the details of doing this arose another issue, simply installing 3rd party Django applications using either easy_install or setup.py. My question is, where should you install a Django application? If looking at Django documentation, one would think to put a Django application inside the project folder. But if your Django application is an egg (a mystifying term in my opinion) and you use easy_install without option '-b' (build-directory) the application will be installed into your current python site-packages directory. Using option '-b' will put a copy of the application in your directory, but still will install it in your current site-packages directory. Then there are other options like --install-dir and prefix. Also how should installation happen when using setup.py which have similar options as buid-directory, install-dir, and prefix?
Is there a 'good practice' standard for installing 3rd party Django applications into a Django project?
Thank a lot,
Todd
They usually aren't installed directly into the project. They're either installed into the system's site-packages/ directory, or in the virtualenv's site-packages/ directory, or in some other well-defined place that the sysadmin has set for this purpose.
This is where virtualenv comes into its own. It basically enables a project-specific site_packages directory, where you can install all the third-party applications that relate to your project. I'd definitely recommend it.
Follow these steps :
change the path according to your local setup
C:\Python27\Lib\site-packages>python pip install django
Create Project
Go to folder where you want to create a project
E:\djangoProject>C:\Python27\Lib\site-packages\django\bin\django-admin.py startproject myproject
python manage.py help is used to list all the commands
Manage.py This file is kind of your project local django-admin for interacting with your project via command line (start the development server, sync db...)
Run Server
E:\djangoProject\myproject>python manage.py runserver
Create App
E:\djangoProject\myproject>python manage.py startapp myapp
Go to myproject settings.py and register your app “myapp” created under INSTALLED_APPS
Migrate DB E:\djangoProject\myproject>python manage.py migrate
Migrate will create necessary tables or collections depending on your db type, necessary for the admin interface to run