Django Shell: play with our data To quickly test our models and the manager, Django provides a very useful tool called Django Shell.
Open a terminal on VSCode (by default it will be opened ad the root of the project). ----------C:\shared\netflix_django\django_netflix_clone> ---------- I can open a terminal on VSCode but when I Run ------- Run: python man shell. A new command prompt will be shown. ---------- I've got the error: C:\shared\netflix_django\django_netflix_clone>python man shell
python: can't open file 'C:\shared\netflix_django\django_netflix_clone\man': [Errno 2] No such file or directory
Also, I don't understand this line........ Import our Movie models: from netflix.models import Movie
Also the line: from netflix.models import Movie is a module importation. It's more a python stuff here. We have a class called Movie inside the file models. Remember that to be able to use a function or class that is not available in a given file, you should import that function or class from it source inside the file that should use it. Let take a simple exemple, guess you have this architechure:
- root |--- file1.py |--- file2.py
And file1.py contains this:
# inside file1.py defutil_function(value):"""Here is an utils function."""print(value)# Do usefull stuff with the value... classUtilClass:"""Here is a util class."""def__init__(self,name):pass
and then you want to use the util_function of the UtilClass inside file2.py, you can import them like this:
# inside file2.py from.file1importutil_function,UtilClass# we can use them util_function(56)utlil_class=UtilClass()
I fyou got that, you should also know that, as we need to import a class or function or module in order to use it in another file, we should import them into django shell too. That why we need to import Movie model if we want to test it into django shell. And becasue the django shell root folder is the project root folder django_netflix_clone, which contains all our app folders modules (netflix included), and also because Movie is inside the path django_netflix_clone/netflix/models.py to import it we do from netflix/models import Movie. Hope that help you.
When you do the python command manage.py makemigrations for the Django migrations topic, you get two categories:
Create Model Movie
Create Model Category I don't get this. I only get init.py. What is the problem for me?
But also in Media, you have two sub-files that appear movies and preview_images. I don't get those categories either. Can you also explain to me where my problem might be?
yes, I added the models code in my models.py file but it didn't work. And I can't go further when I try to replicate your model for the database. Could you help me please ?
Yes, you could either: 1- push the current state of your code on github and send me the link so I'll pull and debug for you Or 2- we could schedule a live pair programming debugging session Which one works best for you ?
Hello all, I setup the virtual environment so I've got the folder estructure. I'm using VScode. I set up the virtual environment on my xampp server. everything was working, folders and files structure. I stopped before to do the migrations. but when I disconnected the ftp from the server and open the project again some of the files had disappeared. there is only two folders and two files: django_netflix_clone django_netflix_clone/ settings.py netflix/ models.py requirements.txt
Hello Orace, Well, yes, I do have auto save enabled on my VScode, and yes I always check if everything has been saved on my server via FTP. Any other ideas? Thx
Hum, I used to work with git, never worked directly with a remote server. Currently I have no cluefor you. But I recommends you to not work directly on the server, work locally on git, and progressivlely commit your changes to git and pull the working branch on your sever.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello everybody, I'm a bit stack here.
Django Shell: play with our data
To quickly test our models and the manager, Django provides a very useful tool called Django Shell.
Open a terminal on VSCode (by default it will be opened ad the root of the project).
----------C:\shared\netflix_django\django_netflix_clone>
---------- I can open a terminal on VSCode but when I Run -------
Run: python man shell. A new command prompt will be shown.
---------- I've got the error:
C:\shared\netflix_django\django_netflix_clone>python man shell
python: can't open file 'C:\shared\netflix_django\django_netflix_clone\man': [Errno 2] No such file or directory
Also, I don't understand this line........
Import our Movie models: from netflix.models import Movie
any help, explain, 💩💩
Also the line:
from netflix.models import Movie
is a module importation. It's more a python stuff here. We have a class calledMovie
inside the filemodels
.Remember that to be able to use a function or class that is not available in a given file, you should import that function or class from it source inside the file that should use it.
Let take a simple exemple, guess you have this architechure:
And
file1.py
contains this:and then you want to use the util_function of the UtilClass inside
file2.py
,you can import them like this:
I fyou got that, you should also know that, as we need to import a class or function or module in order to use it in another file, we should import them into django shell too. That why we need to import
Movie
model if we want to test it into django shell. And becasue the django shell root folder is the project root folderdjango_netflix_clone
, which contains all our app folders modules (netflix
included), and also becauseMovie
is inside the pathdjango_netflix_clone/netflix/models.py
to import it we dofrom netflix/models import Movie
.Hope that help you.
Hello Taller. That might happen because you're on windows instead of linux.
Let me test it on windows and give you a feedback soon.
When you do the python command manage.py makemigrations for the Django migrations topic, you get two categories:
But also in Media, you have two sub-files that appear movies and preview_images. I don't get those categories either. Can you also explain to me where my problem might be?

Hey Yvan, it's not normal indeed. Are you sure you've added the models code into your
models.py
file.yes, I added the models code in my models.py file but it didn't work. And I can't go further when I try to replicate your model for the database. Could you help me please ?
Yes, you could either:
1- push the current state of your code on github and send me the link so I'll pull and debug for you
Or
2- we could schedule a live pair programming debugging session
Which one works best for you ?
Anyways, here is my github email: fayomihorace@gmail.com
Ans if you go for the pair programming, write me to this email folahanfayomi@gmail.com.
For the two sub-files in media folder don't worry, it's not required at this step of the tutorial even though it is in the final source code.
Thank you
Hello all,
I setup the virtual environment so I've got the folder estructure. I'm using VScode.
I set up the virtual environment on my xampp server.
everything was working, folders and files structure.
I stopped before to do the migrations.
but when I disconnected the ftp from the server and open the project again some of the files had disappeared.
there is only two folders and two files:
django_netflix_clone
django_netflix_clone/
settings.py
netflix/
models.py
requirements.txt
can anybody tell me why?
thanks
Are you sure you saved the files before you deconnected from FTP ?
Do you have
auto save
enabled on VScode ?Hello,
What is the way to put this app on a server.
Let's say....
Www.clone.xx
Which is my local server
Thanks
Hello Orace,
Well, yes, I do have auto save enabled on my VScode, and yes I always check if everything has been saved on my server via FTP.
Any other ideas?
Thx
Hum, I used to work with git, never worked directly with a remote server.
Currently I have no cluefor you.
But I recommends you to not work directly on the server, work locally on git, and progressivlely commit your changes to git and pull the working branch on your sever.