-1

i am newer and study django.when i install django_comments , i need add to add a new url and view for django_comments, but it don't work.

comments folder structure:
__init__.py  __pycache__/  forms.py  migrations/  models.py  templates/  urls.py  views.py

__init__.py:
def get_model():
    from comments.models import CommentModel
    return CommentModel

def get_form():
    from comments.forms import CommentForm
    return CommentForm

and forms.py and models.py is fine work.but when i add urls.py, views.py and add the urls to main urls file. it don't work.

urls.py:
from django.urls import path
from . import views

urlpatterns = [
    path('delete/<int:comment_id>/', views.delete_own_comment, 'delete_own_comment'),
]


views.py
from .models import CommentModel

@login_required
def delete_own_comment(request, comment_id):
    comment = get_object_or_404(CommentModel, id=comment_id, site__pk=settings.SITE_ID)
    if comment.user == request.user:
        comment.is_removed = True
        comment.save()

but when i add path('mycomments/', include('comments.urls')) to main urls.py, it run strange errors. can anyone help me???

jett chen
  • 1,067
  • 16
  • 33

1 Answers1

1

It's not

django-admin startapp myapp

It's

python manage.py startapp myapp

Provided that you created before a project with

django-admin startproject myproject
schrodingerscatcuriosity
  • 1,780
  • 1
  • 16
  • 31