Einrichtung einer Unterseite funktioniert nicht

Django, Flask, Bottle, WSGI, CGI…
Antworten
FelixGoesPython
User
Beiträge: 17
Registriert: Mittwoch 25. September 2019, 08:15

Hallo Zusammen. Ich habe jetzt 4x versucht nach Tutorial eine Unterseite anzulegen aber es geht nicht. Kann mir bitte jemand helfen?

Mac Version 10.14.6
Python Version 3.7.4
Django Version 2.1
PyCharm 2019.2.2


New Django Project called „PyShop“


Terminal Window:

„pip install django==2.1“

„django-admin startproject pyshop .“

„python3 manage.py runserver“


When opening http://127.0.0.1:8000 in Safari I see a django page


Open new Terminal Window:
„python3 manage.py startapp products“

Open: PyShop -> products -> migrations -> views.py

from django.http import HttpResponse
from django.shortcuts import render


def index(request):
return HttpResponse('Hello World')


Add new python file to PhyShop -> products folder called „urls“ (-> urls.py)

from django.urls import path
from . import views

urlpattern = [
path('', views.index)
]

Open: PyShop -> pyshop -> urls.py


"""pyshop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('products/', include('products.urls'))
]




When opening http://127.0.0.1:8000/products/ in Safari /chrome I get an error message (browser has no connection to server)

Same for http://127.0.0.1:8000

I also tried https://
Benutzeravatar
sparrow
User
Beiträge: 4193
Registriert: Freitag 17. April 2009, 10:28

Wie hast du denn den Server gestartet, der nicht zu erreichen ist?

Code bitte in Code-Tags (</> Button im vollständigen Editor).

Wie lautet die genaue Fehlermeldung?
Benutzeravatar
__blackjack__
User
Beiträge: 13110
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

Und was sagt das Log vom Server beim Zugriffsversuch?
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
FelixGoesPython
User
Beiträge: 17
Registriert: Mittwoch 25. September 2019, 08:15

Hallo, also das läuft ja über das Program PyCharm auf dem gleichen Mac wie der Browser, den ich benutze. Beim ersten Aufruf wie oben beschrieben, passiert was im Terminal.
Nach Einrichtung der Unterseite, kommt bei Aufruf der Seite keine Aktivität im Terminal zustande (das meinst du mit Logfile des Servers?). Die Fehlermeldung im Browser lautet" Safari kann keine Verbindung zum Server aufbauen".
Sirius3
User
Beiträge: 17750
Registriert: Sonntag 21. Oktober 2012, 17:20

Irgendetwas muß ja im Terminal passieren, wenn der Server abstürzt.
FelixGoesPython
User
Beiträge: 17
Registriert: Mittwoch 25. September 2019, 08:15

OK DAS IST DER TEIL WO DIE ADRESSE AUFRUFBAR IST. ICH MACHE JETZT DIE NÄCHSTEN SCHRITTE UND DANN SCHICKE ICH DEN REST.

ALSO HIER IST DIE WELT NOCH OK:

(venv) Felixs-MacBook-Air:PyShop felixxxxxx$ pip install django==2.1
Collecting django==2.1
Using cached https://files.pythonhosted.org/packages ... ne-any.whl
Collecting pytz (from django==2.1)
Using cached https://files.pythonhosted.org/packages ... ne-any.whl
Installing collected packages: pytz, django
Successfully installed django-2.1 pytz-2019.2
(venv) Felixs-MacBook-Air:PyShop felixxxxxx$ django-admin startproject pyshop .
(venv) Felixs-MacBook-Air:PyShop felixxxxxx$ python3 manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

September 25, 2019 - 18:24:39
Django version 2.1, using settings 'pyshop.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[25/Sep/2019 18:24:46] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[25/Sep/2019 18:24:46] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
[25/Sep/2019 18:24:46] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
[25/Sep/2019 18:24:46] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[25/Sep/2019 18:24:46] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:25:02] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:25:02] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:25:02] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:25:02] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:25:02] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
Not Found: /products/
[25/Sep/2019 18:25:05] "GET /products/ HTTP/1.1" 404 1966
Not Found: /favicon.ico
[25/Sep/2019 18:25:05] "GET /favicon.ico HTTP/1.1" 404 1972
FelixGoesPython
User
Beiträge: 17
Registriert: Mittwoch 25. September 2019, 08:15

OK, ALSO ICH HABE ZWISCHEN ALLEN SCHRITTEN IM BROWSER DIE ADRESSE AUFGERUFEN. BIS ZUM LETZTEN SCHRITT, ALSO BIS DAVOR GEHT ES.

NACH DIESEM SCHRITT GEHT ES NICHT MEHR: Open: PyShop -> pyshop -> urls.py

LOGFILES:

(venv) Felixs-MacBook-Air:PyShop felixxxxxx$ pip install django==2.1
Collecting django==2.1
Using cached https://files.pythonhosted.org/packages ... ne-any.whl
Collecting pytz (from django==2.1)
Using cached https://files.pythonhosted.org/packages ... ne-any.whl
Installing collected packages: pytz, django
Successfully installed django-2.1 pytz-2019.2
(venv) Felixs-MacBook-Air:PyShop felixxxxxx$ django-admin startproject pyshop .
(venv) Felixs-MacBook-Air:PyShop felixxxxxx$ python3 manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

September 25, 2019 - 18:24:39
Django version 2.1, using settings 'pyshop.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[25/Sep/2019 18:24:46] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[25/Sep/2019 18:24:46] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
[25/Sep/2019 18:24:46] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
[25/Sep/2019 18:24:46] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[25/Sep/2019 18:24:46] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:25:02] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:25:02] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:25:02] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:25:02] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:25:02] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
Not Found: /products/
[25/Sep/2019 18:25:05] "GET /products/ HTTP/1.1" 404 1966
Not Found: /favicon.ico
[25/Sep/2019 18:25:05] "GET /favicon.ico HTTP/1.1" 404 1972
Not Found: /products/
[25/Sep/2019 18:34:58] "GET /products/ HTTP/1.1" 404 1966
[25/Sep/2019 18:35:03] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:35:03] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:35:03] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:37:39] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:39] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:37:41] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:40:06] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:40:06] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:40:06] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:40:09] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:41:47] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET / HTTP/1.1" 200 16348
[25/Sep/2019 18:41:47] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[25/Sep/2019 18:41:47] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10dfc08c0>
Traceback (most recent call last):
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 535, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 67, in _load_all_namespaces
namespaces.extend(_load_all_namespaces(pattern, current))
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/felixxxxxx/PycharmProjects/PyShop/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 542, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'products.urls' from '/Users/felixxxxxx/PycharmProjects/PyShop/products/urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
Sirius3
User
Beiträge: 17750
Registriert: Sonntag 21. Oktober 2012, 17:20

Die entscheidende Fehlermeldung steht ganz am Ende: ›does not appear to have any patterns in it‹
Die Datei products/urls.py braucht eine urlpatterns-Variable. Wenn Du genau hinschaust, fehlt die.
FelixGoesPython
User
Beiträge: 17
Registriert: Mittwoch 25. September 2019, 08:15

ach krass, da habe ich einfach immer das "s" vergessen. frage mich was ich bei den ersten versuchen falsch gemacht hatte. Tausend dank jedenfalls, als Anfänger wär ich da nie drauf gekommen. Echt sehr nice, danke :)
Antworten