Django-shortcuts

I am working my way through the w3schools tutorial on Phython.

I am now in the Django-shortcuts part where I am asked to asked to run code on the DOS screen as below:

from django.shortcuts import render
from django.http import HttpResponse
def members(request): return HttpResponse("Hello world!")

I have tried to locate django.shortcuts on my hard drive without success.

I have tried to run this in PyCharm without result.

What am I supposed to do here?

I have attached a screen capture of my DOS environment.

Mike

Any time that you download new SW, during the initial set up process, it always prompts you to verify if the default directory is acceptable. Try downloading it again without actually downloading it again. Just cancel when you come across this step. There you should find the directory where django was download to.

Give it a shot to see if you can find your django.shortcuts.

If it is downloaded via pip, I believe that when you are in the DOS command prompt environment, it also displays where the packages are being downloaded to. It has been a while, but I think if you re-try via pip, it will tell you if your system already has a copy and tell you where it is located.

Paul:

Thank you for staying with me.

I have determined the folder for the django distribution and I can find nothing on django-shortcuts.

I have added this path to the windows environment path and it makes no difference when I run

from django.shortcuts import render

I am including a screen capture of the DOS screen.

Mike

I cannot help with the problem. But please do not use screen shots of text. Please use preformatted text, as you did for the code.
Screen shots make it impossible to copy and quote from.

Hi,

I don’t think that you can enter the following from the DOS command prompt:

from django.shortcuts import render

I believe this is strictly a Python command. This is why you are getting the error:

'from' is not recognized as an internal or external command, ...

I think I might have a potential solution. When you are in the DOS command prompt, go to your working directory (folder), where your active module is located. Once there, type:

python

and hit enter.

This will tell DOS to convert to the Python format. It will then be able to accept Python commands.

As a quick test, do the following.

  1. When you are in the DOS command prompt, enter the following command:
     chdir Desktop
  1. Create a python file named testOnly.
    In it, type the following:
print('I come from the land they call Desktop')

Save this file to the Desktop folder.
3. Back on the DOS command prompt, enter python.
You will see a Python message appear signaling the conversion to the Python environment.

  1. Next, type the following:
import testOnly

You should see the print statement appear.

You don’t want the Django-5.0.1.dist-info folder for this - that only contains metadata for the installation process.

There should be a folder just named django adjacent to that. It will contain either a folder named shortcuts, or a source code file named shortcuts.py.

You do not really want to open, and especially not try to edit, any of this code. There is not really any reason you need to look at this part. It has nothing to do with the process of writing your own code.

As I already explained in the other thread: this does not indicate that there is any problem with your Django installation. There needs to be more code in your program that actually implements the web server. The members function doesn’t do anything by itself.

As I also already explained: you don’t need render yet, because you aren’t using it in your code. PyCharm is warning you about this. It is not an error in the code - it is just an indication that you haven’t finished writing the code yet.

Hi Paul:

When I enter ‘chDir Desktop’ at the DOS Prompt, I get:

The system cannot find the path specified.

Mike

Karl:

I have done my best with the DOS prompt and have a DOS directory as below:

2024-01-29  08:16 PM    <DIR>          .
2024-01-25  11:14 PM    <DIR>          ..
2024-01-28  10:20 PM           108,513 django-admin.exe
2024-01-25  11:15 PM           108,466 f2py.exe
2024-01-29  08:16 PM    <DIR>          myworld
2024-01-25  11:14 PM           108,471 pip.exe
2024-01-25  11:14 PM           108,471 pip3.12.exe
2024-01-25  11:14 PM           108,471 pip3.exe
2024-01-28  10:19 PM           108,466 sqlformat.exe
2024-01-25  11:14 PM           108,458 wheel.exe
               7 File(s)        759,316 bytes
               3 Dir(s)  152,492,621,824 bytes free

C:\Users\donca\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts>

It seems that Django is called django-admin.exe and there is no subfolder called Shortcuts.

I have a feeling that the w3schools tutorial was written a few years ago and Django has evolved somewhat.

I have done a search on my hard drive, there is no Django.exe only Django-admin.exe.

Mike

Hi,

there are no capitals.

just type:

chdir desktop

remember, this is just arbitrary since I am assuming that you created a Python file with the code
from the previous post and that you saved it to your desktop folder. If you had saved it to another
folder, then you should have moved to that directory in DOS.

Just my opinion, I suggest you put Django to the side and instead focus on learning Python
fundamentals. Django is a full fledged professional grade application which requires a higher
level of Python understanding.

There is no such thing as “a DOS directory”. You are looking at the Scripts directory of your Python installation, yes.

This contains a separate program, that has nothing to do with your Python code, called django-admin.exe. This is a program that you get when you install Django, completely aside from the Django library that you use to write your code.

None of the relevant Django library code is in this folder. You also don’t need to look at it in order to write your code.

The problem you encountered, again, has nothing to do with any of this.

It has nothing to do with any changes in Django. It has to do with the fact that the tutorial is expecting you to understand certain things about how computers work. You seem to be missing a lot of these concepts, which results in repeatedly misusing terminology in ways that don’t make any sense.

My strong recommendation is to find and follow a DOS tutorial first, then a Python tutorial, and only then think about Django.

There is no reason to expect to find a “Django.exe” anywhere on your hard drive, and no reason to expect a shortcuts folder in the place you are looking. When I said

this did not mean anything to do with the folder you are now looking at. It should be in the site-packages folder, not the Scripts folder. But again, there is no reason to look on the hard drive for this content, because the problem you encountered does not suggest there is anything wrong or missing with the installation.