adamspd / django-appointment

A Django app for managing appointment scheduling with ease and flexibility.
Apache License 2.0
89 stars 30 forks source link

404 error when running server #126

Closed sati-bodhi closed 4 months ago

sati-bodhi commented 4 months ago

Describe the bug I run into a 404 error when running the server for the first time.

To Reproduce Steps to reproduce the behavior:

  1. Follow these instructions
  2. python manage.py runserver
  3. Admin panel is accessible, but main site is not.
  4. See error.

Expected behavior Base url brings us to a landing page for making appointments.

Screenshots If applicable, add screenshots to help explain your problem. image

image

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

settings.py

"""
Django settings for appointments project.

Generated by 'django-admin startproject' using Django 4.1.6.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
from pathlib import Path

from django.conf import locale
from django.utils.translation import gettext_lazy as _
from dotenv import load_dotenv

load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-(%st!9pc%2d%*b3xt8@0o7*4rkxq-$6j3y-(b*ftz^m2^r4l$z"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]

# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    'appointment.apps.AppointmentConfig',
    'django_q',
    ]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    'django.middleware.locale.LocaleMiddleware',
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "appointments.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / 'appointment/templates']
        ,
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    },
]

WSGI_APPLICATION = "appointments.wsgi.application"

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
    },
]

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = "en"

TIME_ZONE = 'Asia/Singapore'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = "/static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, "appointment/static")]

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

APPOINTMENT_BUFFER_TIME = 0

LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")]
LANGUAGES = (
    ('en', _('English')),
    ('es', _('Spanish')),
    ('fr', _('French')),
)

# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', default="")
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', default="")
EMAIL_USE_TLS = True
EMAIL_SUBJECT_PREFIX = ""
EMAIL_USE_LOCALTIME = True
SERVER_EMAIL = EMAIL_HOST_USER

ADMINS = [
    ('Adams', "adamspd.developer@gmail.com"),
]

Q_CLUSTER = {
    'name': 'DjangORM',
    'workers': 4,
    'timeout': 90,
    'retry': 120,
    'queue_limit': 50,
    'bulk': 10,
    'orm': 'default',
}

urls.py

"""appointments URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.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.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.urls import include, path

urlpatterns = i18n_patterns(
    path("admin/", admin.site.urls),
    path('i18n/', include('django.conf.urls.i18n')),
    path("appointment/", include("appointment.urls")),
)

Can you fix the bug?

adamspd commented 4 months ago

Hi @sati-bodhi,

Thank you for bringing this to my attention and for trying out the package. I realize now that the documentation might not have been clear on how to access the main site of the package within your project. My apologies for any confusion this has caused.

The behaviour you're experiencing is actually by design, though it might not have been immediately obvious. The root URL (127.0.0.1:8000/) is intentionally reserved for your project's own use. To access the features of the package, you should use the /appointment/ prefix in the URL (only when using it when installed in a project via pip install command), as per the error message you encountered.

For example, to start exploring the package's capabilities, you can navigate to http://127.0.0.1:8000/appointment/... after integrating it into your Django project.

Here are some specific URLs you can try to access various features (Note: If your project is set up with internationalization, you might need to add the language prefix, like en/, to the URLs). Note once again that you have to add appointment/ after the /en if you have installed the package on a project, but if you're trying it as is, use the URLs below:

The comprehensive list of accessible URLs and their functions can be found in our documentation here.

Additionally, I've created a brief video tutorial (without audio) to demonstrate how to access and utilize these features effectively. You can watch it here.

I hope this clears up any confusion and helps you make the most out of our package. If you have any further questions or need additional assistance, please don't hesitate to ask.

Best regards,

Adams

adamspd commented 4 months ago

See how I used the package in this project: https://github.com/adamspd/crueltouch

Live site where I listed the service a client can make an appointment for: https://tchiiz.com/services/

sati-bodhi commented 4 months ago
  • To view all appointments (as an admin, post-login to Django admin): http://127.0.0.1:8000/en/app-admin/appointments

    • To create an appointment (as a client, ensure services and staff availability are set up): http://127.0.0.1:8000/en/request/1/ where 1 is the ID of the service you're booking.

    • To view a staff member's profile: http://127.0.0.1:8000/en/app-admin/user-profile/

    • To schedule days-off for a staff member: http://127.0.0.1:8000/en/app-admin/add-day-off/1/

    • To set working hours for a staff member: http://127.0.0.1:8000/en/app-admin/add-working-hours/1/

    • To view a staff member's appointments in a calendar view: http://127.0.0.1:8000/en/app-admin/appointments/

Neither of these URLs worked for me.

image

sati-bodhi commented 4 months ago

Can you advise how to integrate the App into an existing project? Git clone in the existing project folder is going to nest the App project folder within another project (which is probably not how django apps work.)

adamspd commented 4 months ago

Hi @sati-bodhi,

I understand there's been some confusion regarding accessing the URLs after integrating the django-appointment package into your project. Let's clarify how Django's URL dispatcher works in conjunction with the package, so you can smoothly navigate through it.

When you incorporate django-appointment into your Django project, you decide how to route the URLs defined by the package within your application. This is determined by how you include the package's URLs in your project's urls.py file. Here’s how it works:

If your urls.py includes the line (as you said you added in your issue):

path("appointment/", include("appointment.urls")),

you're specifying that every URL from the django-appointment should be accessed by prefixing it with appointment/. It's a way to namespace the package URLs within your project. This means, for every URL provided by django-appointment, you need to prepend appointment/ to it when accessing it.

For example, if you had set it up like this:

path("custom-link/", include("appointment.urls")),

then, you'd access the package's URLs by prefixing them with custom-link/ instead.

Given your current setup, here’s how you should modify the URLs I previously mentioned:

Remember, the en/ prefix is used here to indicate the use of internationalization in your project. If your project does not use internationalization, or if you are accessing URLs in a different language, adjust accordingly.

In my earlier communication, I provided URLs without the appointment/ prefix, assuming you were directly experimenting with the repository rather than integrating the package into your project. This assumption led me to overlook the necessity of including the appointment/ prefix, which is essential when the package is installed and used within a Django project environment. This oversight was due to the fact that, in direct repository testing scenarios, namespace considerations like appending appointment/or any custom namespace you choose (i.e custom-link/ as explain above) to URLs are not applicable. My apologies for any confusion this may have caused.

One more important point: for customization, please read this documentation, it may help in setting up the project.

I trust this explanation clarifies the URL structure for accessing the django-appointment package's features within your project. Should you have further questions or need additional guidance, please don't hesitate to reach out. Conversely, if this comment addresses your issue, I'd appreciate it if you could confirm its resolution in a comment and close the issue when convenient. Furthermore, if you find value in the project, consider starring it on GitHub—your support would be greatly appreciated.

Best regards,

Adams

adamspd commented 4 months ago

Hi @sati-bodhi, is this issue still needed ? Thanks in advance for closing it if not needed anymore.