Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Create the "nearbyshops" App

In this video you will be creating a Django app. You’ve already created the Django project which is the main entry point to your website.

This is the current structure of your web app so far. What you are looking at is considered the Django project portion of your web application.

You can see the utilities are there for configuration and routing, but there are no web pages yet, and no interactivity.

This is where the Django app comes in. A request will arrive at the front door of our Django project. Urls.py will determine the destination view for the particular request and direct it to the appropriate Django app.

00:00 Welcome to video number six in this series on making a location-based web app in Django and GeoDjango. In this video, you will be creating a Django app. You’ve already created the Django project, which is the main entry point to your website.

00:16 This is the current structure of your web app so far. What you are looking at is considered the Django project portion of your web application. You can see the utilities are there for configuration and routing, but there are no web pages yet and no interactivity.

00:31 This is where the Django app comes into play. A request will arrive at the front door of our Django project. urls.py will determine the destination view for the particular request and direct it to the appropriate Django app.

00:47 The app, in turn, may have its own urls.py to do additional routing, or it processes the corresponding view specified in the main urls.py.

00:57 A response is then formed and sent back through the main site.

01:03 With the shops project in place, you will create the nearbyshops app. Your shops project can have multiple apps, but for this tutorial you will only be creating one.

01:15 To create a Django app in a project, use the manage.py utility created by the project script when the project was initiated. At your terminal prompt, type python manage.py startapp nearbyshops.

01:31 Let’s see the effect of the startapp script. Notice a new folder has been created with the name of our app. Inside, there are some additional files. The app was successfully created.

01:43 But there’s one more step. The shops project needs to know about the new app, therefore we need to add it to the INSTALLED_APPS list in settings.py.

01:53 The nearbyshops app is now a component of the shops project—great job! You’ve done a lot of work and you may be curious to see if your website starts.

02:02 Let’s see! To launch your site, use the manage.py utility again. At your terminal prompt type python manage.py runserver.

02:13 Your website should launch on localhost port 8000. Click the loopback URL provided by the runserver output. You should see the default page for a new Django project.

02:25 To stop your site just press Control + C back in your terminal. The next step is to get our model set up and some data into our database. Let’s do that in the next video.

Avatar image for Orephia

Orephia on Sept. 3, 2021

@Bartosz when I try this command in my venv I get this error: Failed building wheel for psycopg2-binary, so I just copied the package into the venv

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Sept. 3, 2021

@Orephia There can be many reasons for failure, which can be hard to tell without seeing your specific error message. It should contain some clues as to what went wrong. Do you want to share it?

Avatar image for Orephia

Orephia on Sept. 3, 2021

@Bartosz here is the full message i get when I try installing it:

PS C:\Users\JIHANE\PycharmProjects\geoApp> pip install psycopg2-binary
WARNING: Ignoring invalid distribution -ip (c:\users\jihane\pycharmprojects\geoapp\venv\lib\python3.8\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\users\jihane\pycharmprojects\geoapp\venv\lib\python3.8\site-packages)
Collecting psycopg2-binary
  Using cached psycopg2-binary-2.9.1.tar.gz (380 kB)
Building wheels for collected packages: psycopg2-binary
  Building wheel for psycopg2-binary (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\jihane\pycharmprojects\geoapp\venv\bin\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\JIHANE\\AppDat
a\\Local\\Temp\\pip-install-pzj0wf0i\\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\\setup.py'"'"'; __file__='"'"'C:\\Users\\JIHANE\\AppData\\Local\\Temp\\pip-inst
all-pzj0wf0i\\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else i
o.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"
'))' bdist_wheel -d 'C:\Users\JIHANE\AppData\Local\Temp\pip-wheel-8hsv9bs2'
       cwd: C:\Users\JIHANE\AppData\Local\Temp\pip-install-pzj0wf0i\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\
  Complete output (48 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.mingw-3.8
  creating build\lib.mingw-3.8\psycopg2
  copying lib\errorcodes.py -> build\lib.mingw-3.8\psycopg2
  copying lib\errors.py -> build\lib.mingw-3.8\psycopg2
  copying lib\extensions.py -> build\lib.mingw-3.8\psycopg2
  copying lib\extras.py -> build\lib.mingw-3.8\psycopg2
  copying lib\pool.py -> build\lib.mingw-3.8\psycopg2
  copying lib\sql.py -> build\lib.mingw-3.8\psycopg2
  copying lib\tz.py -> build\lib.mingw-3.8\psycopg2
  copying lib\_ipaddress.py -> build\lib.mingw-3.8\psycopg2
  copying lib\_json.py -> build\lib.mingw-3.8\psycopg2
  copying lib\_range.py -> build\lib.mingw-3.8\psycopg2
  copying lib\__init__.py -> build\lib.mingw-3.8\psycopg2
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build\temp.mingw-3.8
  creating build\temp.mingw-3.8\psycopg
  C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -Wno-unused-result -Wsign-compare -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDIO=
1 -D_WIN32_WINNT=0x0601 -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -D_WIN32_WINNT=0x0601 -DNDEBUG "-DPSYCOPG_VERSION=2.9.1 (dt
 dec pq3 ext lo64)" -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=100018 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -IC:\users\jihane\pycharmprojects\geoapp\venv\include -IC:\msys64\mingw6
4\include\python3.8 -I. -IC:/PROGRA~1/POSTGR~1/10/include -IC:/PROGRA~1/POSTGR~1/10/include/server -c psycopg\psycopgmodule.c -o build\temp.mingw-3.8\psycopg\psycopgm
odule.o -O3 -fno-strict-aliasing
  In file included from ./psycopg/config.h:164,
                   from ./psycopg/psycopg.h:38,
                   from psycopg\psycopgmodule.c:28:
  ./psycopg/win32_support.h:43:6: error: #elif with no expression
     43 | #elif
        |      ^
  In file included from ./psycopg/psycopg.h:38,
                   from psycopg\psycopgmodule.c:28:
  psycopg\psycopgmodule.c: In function 'psyco_connect':
  ./psycopg/config.h:58:49: warning: implicit declaration of function 'getpid'; did you mean 'getcwd'? [-Wimplicit-function-declaration]
     58 |         fprintf(stderr, "[%d] " fmt "\n", (int) getpid() , ## args)
        |                                                 ^~~~~~
  psycopg\psycopgmodule.c:95:5: note: in expansion of macro 'Dprintf'
     95 |     Dprintf("psyco_connect: dsn = '%s', async = %d", dsn, async);
        |     ^~~~~~~

  It appears you are missing some prerequisite to build the package from source.

  You may install a binary package by installing 'psycopg2-binary' from PyPI.
  If you want to install psycopg2 from source, please install the packages
  required for the build and try again.

  For further information please check the 'doc/src/install.rst' file (also at
  <https://www.psycopg.org/docs/install.html>).

  error: command 'C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2-binary
  Running setup.py clean for psycopg2-binary
Failed to build psycopg2-binary
WARNING: Ignoring invalid distribution -ip (c:\users\jihane\pycharmprojects\geoapp\venv\lib\python3.8\site-packages)
Installing collected packages: psycopg2-binary
    Running setup.py install for psycopg2-binary ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\jihane\pycharmprojects\geoapp\venv\bin\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\JIHANE\\AppD
ata\\Local\\Temp\\pip-install-pzj0wf0i\\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\\setup.py'"'"'; __file__='"'"'C:\\Users\\JIHANE\\AppData\\Local\\Temp\\pip-in
stall-pzj0wf0i\\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else
 io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"
'"'))' install --record 'C:\Users\JIHANE\AppData\Local\Temp\pip-record-dyc2t1x3\install-record.txt' --single-version-externally-managed --compile --install-headers 'C
:\users\jihane\pycharmprojects\geoapp\venv\include\site\python3.8\psycopg2-binary'
         cwd: C:\Users\JIHANE\AppData\Local\Temp\pip-install-pzj0wf0i\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\
    Complete output (48 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.mingw-3.8
    creating build\lib.mingw-3.8\psycopg2
    copying lib\errorcodes.py -> build\lib.mingw-3.8\psycopg2
    copying lib\errors.py -> build\lib.mingw-3.8\psycopg2
    copying lib\extensions.py -> build\lib.mingw-3.8\psycopg2
    copying lib\extras.py -> build\lib.mingw-3.8\psycopg2
    copying lib\pool.py -> build\lib.mingw-3.8\psycopg2
    copying lib\sql.py -> build\lib.mingw-3.8\psycopg2
    copying lib\tz.py -> build\lib.mingw-3.8\psycopg2
    copying lib\_ipaddress.py -> build\lib.mingw-3.8\psycopg2
    copying lib\_json.py -> build\lib.mingw-3.8\psycopg2
    copying lib\_range.py -> build\lib.mingw-3.8\psycopg2
    copying lib\__init__.py -> build\lib.mingw-3.8\psycopg2
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build\temp.mingw-3.8
    creating build\temp.mingw-3.8\psycopg
    C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -Wno-unused-result -Wsign-compare -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDI
O=1 -D_WIN32_WINNT=0x0601 -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -D_WIN32_WINNT=0x0601 -DNDEBUG "-DPSYCOPG_VERSION=2.9.1 (
dt dec pq3 ext lo64)" -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=100018 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -IC:\users\jihane\pycharmprojects\geoapp\venv\include -IC:\msys64\ming
w64\include\python3.8 -I. -IC:/PROGRA~1/POSTGR~1/10/include -IC:/PROGRA~1/POSTGR~1/10/include/server -c psycopg\psycopgmodule.c -o build\temp.mingw-3.8\psycopg\psycop
gmodule.o -O3 -fno-strict-aliasing
    In file included from ./psycopg/config.h:164,
                     from ./psycopg/psycopg.h:38,
                     from psycopg\psycopgmodule.c:28:
    ./psycopg/win32_support.h:43:6: error: #elif with no expression
       43 | #elif
          |      ^
    In file included from ./psycopg/psycopg.h:38,
                     from psycopg\psycopgmodule.c:28:
    psycopg\psycopgmodule.c: In function 'psyco_connect':
    ./psycopg/config.h:58:49: warning: implicit declaration of function 'getpid'; did you mean 'getcwd'? [-Wimplicit-function-declaration]
       58 |         fprintf(stderr, "[%d] " fmt "\n", (int) getpid() , ## args)
          |                                                 ^~~~~~
    psycopg\psycopgmodule.c:95:5: note: in expansion of macro 'Dprintf'
       95 |     Dprintf("psyco_connect: dsn = '%s', async = %d", dsn, async);
          |     ^~~~~~~

    It appears you are missing some prerequisite to build the package from source.

    You may install a binary package by installing 'psycopg2-binary' from PyPI.
    If you want to install psycopg2 from source, please install the packages
    required for the build and try again.

    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).

    error: command 'C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\jihane\pycharmprojects\geoapp\venv\bin\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[
0] = '"'"'C:\\Users\\JIHANE\\AppData\\Local\\Temp\\pip-install-pzj0wf0i\\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\\setup.py'"'"'; __file__='"'"'C:\\Users\\JIH
ANE\\AppData\\Local\\Temp\\pip-install-pzj0wf0i\\psycopg2-binary_5b64c7c3d4fc40b48190d0f875ff1642\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__)
 if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(co
mpile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\JIHANE\AppData\Local\Temp\pip-record-dyc2t1x3\install-record.txt' --single-version-externally-manag
ed --compile --install-headers 'C:\users\jihane\pycharmprojects\geoapp\venv\include\site\python3.8\psycopg2-binary' Check the logs for full command output.
WARNING: Ignoring invalid distribution -ip (c:\users\jihane\pycharmprojects\geoapp\venv\lib\python3.8\site-packages)
WARNING: Ignoring invalid distribution -ip (c:\users\jihane\pycharmprojects\geoapp\venv\lib\python3.8\site-packages)
Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Sept. 6, 2021

@Orephia It appears that there’s no prebuilt binary available for your platform, and the pip command resorts to trying to compile the library from source code using the Mingw compiler. The error message suggests there might be some missing prerequisites and links to the official documentation at www.psycopg.org/docs/install.html for more detail. I’m afraid I can’t help you more with this. Sorry…

Avatar image for Kale OHara

Kale OHara on July 26, 2022

Hey Y’all, I’m running a MacOS Monterey (12.2.1) and am getting the “ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried “gdal”, “GDAL”, “gdal3.3.0”, “gdal3.2.0”, “gdal3.1.0”, “gdal3.0.0”, “gdal2.4.0”, “gdal2.3.0”, “gdal2.2.0”, “gdal2.1.0”, “gdal2.0.0”). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings” error that everyone hits. Qgis can run with the latest python3 version so I’m not sure why it’s still hitting this wall. I tried the “brew install gdal” and it installs fine but doesn’t fix the problem. This error message pops up when I try to run “python manage.py runserver”.

Avatar image for Martin Breuss

Martin Breuss RP Team on July 28, 2022

Kale OHara did you install also the gdal Python package:

(venv) $ python -m pip install gdal

Make sure that you’ve done this in your virtual environment, and that you can confirm that the package is accessible in the same environment as your Django app.

If you’re still running into the same error, maybe one of these answers can help?

Avatar image for Dee82

Dee82 on Nov. 8, 2023

Ran into the same error on windows 10 with QGIS 3.28.12 with the GDAL dll not being found. After several hours of searching for options, trial and error , I was finally able to resolve it using a combination of what dthomas01 posted and this post:stackoverflow.com/questions/71847139/solution-to-installing-gdal-proj-geos-in-windows-10-for-django-geodjango

Thanks for posting dthomas01, that helped put me on the right path!!

Avatar image for johnlukow

johnlukow on March 3, 2024

I’m struggling with this tutorial. I got the nearbyshops app working by adding: GDAL_LIBRARY_PATH = r’C:\Program Files\QGIS 3.36.0\bin\gdal308.dll’ and changing ENGINE’: ‘django.db.backends.postgresql’ in settings.py. Hopefully I can keep moving now.

Avatar image for Thierry Gagné

Thierry Gagné on Oct. 2, 2024

I have also ran into the common problem that my program could not find the GDAL library (on a Mac). Running “brew install gdal” also solved my problem.

I am just leaving a comment to highlight that having to waste an hour to understand a problem has left me with a negative impression of this website.

I have loved the content so far, but it makes absolutely no sense to not re-do this content if people have been have the same problems for five years! Now, I don’t know if downloading QGIS was the right method or if I could have done something much simpler.

Avatar image for Martin Breuss

Martin Breuss RP Team on Oct. 4, 2024

@Thierry Gagné thanks for mentioning, and for bumping this course back up on our priorities list for updates. You’re right that we should have already tackled updates for this course a while ago 😳

We’re actively working on getting older and outdated content up to date, but it takes some juggling to continue creating new content at the same time. Anyways, I’ll make sure to get this course slated for an update as soon as possible.

Thanks everyone for commenting and providing solutions!

Become a Member to join the conversation.