The current path, index.php, didn’t match any of these - django
**
Good day, please am new to Django and am facing some challenges
which have tried to resolve but am not yet resolve please i need
your help.
**
the error are below
Page not found (404)
Request Method: GET
Request URL: https://mydomain/pages/index.php**
Using the URLconf defined in dcitygate.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
blog/ [name='blog']
audio_messages/ [name='audio_messages']
imgc/ [name='imgc']
imgc/<int:id> [name='imgc_detail']
tsc/ [name='tsc']
tsc/<int:id> [name='tsc_detail']
word_prayer/ [name='word_prayer']
word_prayer/<int:id> [name='word_prayer_detail']
video_messages/ [name='video_messages']
contact_us/ [name='contact_us']
couple_meeting/ [name='couple_meeting']
kcc/ [name='kcc']
kcc/<int:id> [name='kcc_detail']
pages/streaming/ [name='streaming']
watchlive/ [name='watchlive']
<int:id> [name='audio_streaming_detail']
listenlive/ [name='listenlive']
blogs/
audio_msg/
^media/(?P<path>.*)$'''
*The current path, index.php, didn’t match any of these*
my Project.url
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls import url
urlpatterns = [
path('admin/',admin.site.urls),
path('', include('pages.urls')),
path('blogs/', include('blogs.urls')),
path('audio_msg/', include('audio_msg.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
MyApp.url
from django.urls import path, re_path
from django.conf.urls import url
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('blog/',views.blog, name='blog'),
path('audio_messages/', views.audio_messages, name='audio_messages'),
path('imgc/', views.imgc, name='imgc'),
path('imgc/<int:id>', views.imgc_detail, name='imgc_detail'),
path('tsc/', views.tsc, name='tsc'),
path('tsc/<int:id>', views.tsc_detail, name='tsc_detail'),
path('word_prayer/', views.word_prayer, name='word_prayer'),
path('word_prayer/<int:id>', views.word_prayer_detail, name='word_prayer_detail'),
path('video_messages/', views.video_messages, name='video_messages'),
path('contact_us/', views.contact_us, name='contact_us'),
path('couple_meeting/', views.couple_meeting, name='couple_meeting'),
path('kcc/', views.kcc, name='kcc'),
path('kcc/<int:id>', views.kcc_detail, name='kcc_detail'),
path('pages/streaming/', views.streaming, name='streaming'),
path('watchlive/', views.watchlive, name='watchlive'),
path('<int:id>', views.audio_streaming_detail, name='audio_streaming_detail'),
path('listenlive/', views.listenlive, name='listenlive'),
]
my view
from django.shortcuts import render, get_object_or_404
from blogs.models import Blog
from audio_msg.models import Audio_msg
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# Create your views here.
def index(request):
blog_data = Blog.objects.order_by('-created_date')
audio_data = Audio_msg.objects.order_by('-created_date')
data = {
'blog_data': blog_data,
'audio_data': audio_data,
}
return render(request, 'pages/home.html', data)
def blog(request):
return render(request, 'pages/blog.html')
def audio_messages(request):
return render(request, 'pages/audio_messages.html')
def imgc(request):
blog_data = Blog.objects.order_by('-created_date').filter(category='IMGC')
paginator = Paginator(blog_data, 9)
page = request.GET.get('page')
paged_blog = paginator.get_page(page)
data = {
'blog_data': paged_blog,
}
return render(request, 'pages/imgc.html', data)
def imgc_detail(request, id):
blog_detail = get_object_or_404(Blog, pk=id)
data = {
'blog_detail': blog_detail,
}
return render(request, 'pages/imgc_detail.html', data)
def tsc(request):
blog_data = Blog.objects.order_by('-created_date').filter(category='TSC')
paginator = Paginator(blog_data, 9)
page = request.GET.get('page')
paged_blog = paginator.get_page(page)
data = {
'blog_data': paged_blog,
}
return render(request, 'pages/tsc.html', data)
def tsc_detail(request, id):
blog_detail = get_object_or_404(Blog, pk=id)
data = {
'blog_detail': blog_detail,
}
return render(request, 'pages/tsc_detail.html', data)
def word_prayer(request):
blog_data = Blog.objects.order_by('-created_date').filter(category='WAP')
paginator = Paginator(blog_data, 9)
page = request.GET.get('page')
paged_blog = paginator.get_page(page)
data = {
'blog_data': paged_blog,
}
return render(request, 'pages/word_prayer.html', data)
def word_prayer_detail(request, id):
blog_detail = get_object_or_404(Blog, pk=id)
data = {
'blog_detail': blog_detail,
}
return render(request, 'pages/word_prayer_detail.html', data)
def video_messages(request):
return render(request, 'pages/video_messages.html')
def audio_messages(request):
return render(request, 'pages/audio_messages.html')
def contact_us(request):
return render(request, 'pages/contact_us.html')
def couple_meeting(request):
return render(request, 'pages/couple_meeting.html')
def kcc(request):
blog_data = Blog.objects.order_by('-created_date').filter(category='KCC')
data = {
'blog_data': blog_data,
}
return render(request, 'pages/kcc.html', data)
def kcc_detail(request, id):
blog_detail = get_object_or_404(Blog, pk=id)
data = {
'blog_detail': blog_detail,
}
return render(request, 'pages/kcc_detail.html', data)
def streaming(request):
return render(request, 'pages/streaming.html')
def watchlive(request):
return render(request, 'pages/watchlive.html')
def listenlive(request):
return render(request, 'pages/listenlive.html')
def audio_msg(request):
audio_data = Audio_msg.objects.order_by('-created_date')
data = {
'audio_data': audio_data,
}
return render(request, 'pages/audio_msg.html', data)
def audio_streaming_detail(request, id):
audio_data = get_object_or_404(Audio_msg, pk=id)
data = {
'audio_data': audio_data,
}
**return render(request, 'pages/audio_streaming_detail.html', data)
please help**
I don't see any pages/index.php anywhere, and you shouldn't use .php on Django projects, it's not PHP
If you're trying to get to: path('', views.index, name='index') just try http://127.0.0.1:8000/
If you are trying to get to another view, what view?- ti should be in a urls.py
Thank you for this platform and everyone that have contributed to this question.
my solution to the problem was removing the default redirect code in .htaccess and use this code below.
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home2/thecity2/church-project"
PassengerBaseURI "/"
PassengerPython "/home2/thecity2/virtualenv/church-project/3.9/bin/python"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END
Related
Reverse for 'new-quiz' with arguments '(11, '')' not found. 1 pattern(s) tried: ['course/(?P<course_id>[^/]+)/(?P<module_id>[^/]+)/quiz/newquiz$']
here is my code views.py from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth.decorators import login_required from django.http import HttpResponseForbidden from quiz.forms import NewQuizForm, NewQuestionForm from quiz.models import Answer, Question, Quizzes, Attempter, Attempt from courses.models import Module from completion.models import Completion # Create your views here. def NewQuiz(request, course_id, module_id): user = request.user module = get_object_or_404(Module, id=module_id) if request.method == 'POST': form = NewQuizForm(request.POST) if form.is_valid(): title = form.cleaned_data.get('title') description = form.cleaned_data.get('description') due = form.cleaned_data.get('due') allowed_attempts = form.cleaned_data.get('allowed_attempts') time_limit_mins = form.cleaned_data.get('time_limit_mins') quiz = Quizzes.objects.create(user=user, title=title, description=description, due=due, allowed_attempts=allowed_attempts, time_limit_mins=time_limit_mins) module.quizzes.add(quiz) module.save() return redirect('new-question', course_id=course_id, module_id=module_id, quiz_id=quiz.id) else: form = NewQuizForm() context = { 'form': form, } return render(request, 'quiz/newquiz.html', context) def NewQuestion(request, course_id, module_id, quiz_id): user = request.user quiz = get_object_or_404(Quizzes, id=quiz_id) if request.method == 'POST': form = NewQuestionForm(request.POST) if form.is_valid(): question_text = form.cleaned_data.get('question_text') points = form.cleaned_data.get('points') answer_text = request.POST.getlist('answer_text') is_correct = request.POST.getlist('is_correct') question = Question.objects.create(question_text=question_text, user=user, points=points) for a, c in zip(answer_text, is_correct): answer = Answer.objects.create(answer_text=a, is_correct=c, user=user) question.answers.add(answer) question.save() quiz.questions.add(question) quiz.save() return redirect('new-question', course_id=course_id, module_id=module_id, quiz_id=quiz.id) else: form = NewQuestionForm() context = { 'form': form, } return render(request, 'quiz/newquestion.html', context) def QuizDetail(request, course_id, module_id, quiz_id): user = request.user quiz = get_object_or_404(Quizzes, id=quiz_id) my_attempts = Attempter.objects.filter(quiz=quiz, user=user) context = { 'quiz': quiz, 'my_attempts': my_attempts, 'course_id': course_id, 'module_id': module_id, } return render(request, 'quiz/quizdetail.html', context) and quiz/urls.py from django.urls import path from . import views urlpatterns = [ path('<course_id>/<module_id>/quiz/newquiz', views.NewQuiz, name='new-quiz'), path('<course_id>/modules/<module_id>/quiz/<quiz_id>/newquestion', views.NewQuestion, name='new-question'), path('<course_id>/modules/<module_id>/quiz/<quiz_id>/', views.QuizDetail, name='quiz-detail'), path('<course_id>/modules/<module_id>/quiz/<quiz_id>/take', views.TakeQuiz, name='take-quiz'), path('<course_id>/modules/<module_id>/quiz/<quiz_id>/take/submit', views.SubmitAttempt, name='submit-quiz'), path('<course_id>/modules/<module_id>/quiz/<quiz_id>/<attempt_id>/results', views.AttemptDetail, name='attempt-detail'), ] and template <i class="material-icons"></i>Add new quiz in the project urls.py path('quiz/',include('quiz.urls')), it says like this "Reverse for 'new-quiz' with arguments '(11, '')' not found. 1 pattern(s) tried: ['course/(?P<course_id>[^/]+)/(?P<module_id>[^/]+)/quiz/newquiz$']"which means it detect the first argument but not the others why???
Use single quotes in your template, so 'new-quiz' instead of "new-quiz": <i class="material-icons"></i>Add new quiz
'Tribe' object has no attribute 'tribe_id'
I have a view which should redirect the user to the new tribe that he created. but I don't know how to get the tribe_id for it to work. views.py def tribeview(request, tribe_id): tribe = get_object_or_404(Tribe,pk=tribe_id) playlist = tribe.playlist_set.all() context = { 'tribe': tribe, 'playlists':playlist } return render(request, 'app/tribe.html', context) class create_tribe(CreateView): model = Tribe form_class = TribeForm template_name = 'app/create_tribe.html' def form_valid(self, form): tribe = form.save(commit=False) tribe.chieftain = self.request.user tribe.save() return super().form_valid(form) def get_success_url(self): return reverse('app:tribe-view', args={'tribe': self.object.tribe_id}) urls.py app_name = 'app' urlpatterns = [ path('', views.index, name='index'), path('tribe/<int:tribe_id>',views.tribeview,name='tribe-view'), path('tribe/<int:tribe_id>/playlist/<int:playlist_id>',views.playlistview,name='playlist-view'), path('new_tribe', login_required(create_tribe.as_view()), name="new-tribe"), ] models.py class Tribe(TimeStamped): name = models.CharField(max_length=200,unique=True) chieftain = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE) tribe_members = models.ManyToManyField(Member) def __str__(self): return self.name[:80]
django - Upload page must only be accessible once the form is submitted. Directly entering the upload url should not work
Uploading a file is only allowed once the form is submitted. The upload url must not be accessible otherwise. After the user logs in, the upload url is directly accessed. How can i restrict this? This will create multiple entries of file upload for the same form models.py class uploadmeta(models.Model): path = models.ForeignKey(Mdform, verbose_name="ID", on_delete=models.PROTECT) user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) datafile = models.FileField(upload_to=get_upload_folder, verbose_name="Dataset", validators=[validate_file_extension]) def get_absolute_url(self): return reverse('file_list', kwargs={'pk': self.pk}) views.py if request.user.is_authenticated: if request.method == 'POST': form = uploadmetaform(request.POST, request.FILES) if form.is_valid(): path = form.cleaned_data['path'] if uploadmeta.objects.filter(path=path).exists(): user = form.cleaned_data['user'] datafile = form.cleaned_data['datafile'] context = { 'path': path, 'user': user, 'datafile': datafile } template = loader.get_template('nameexists.html') return HttpResponse(template.render(context, request)) else: user = form.cleaned_data['user'] datafile = form.cleaned_data['datafile'] path = dict(form.fields['path'].path)[path] print(path) b = form(path=path, user=user, datafile=datafile) b.save() context = { 'path': path, 'user': user, 'datafile': datafile } template = loader.get_template('thankyou.html') return HttpResponse(template.render(context, request)) else: form = uploadmetaform() return render(request, 'uploaddata.html', {'form': form}) else: return render(request, 'home.html')```
from django.shortcuts import render from basicform.forms import BasicForm from django.template import loader from django.http import HttpResponse from basicform.choices import * from basicform.models import BasicFormModel def responseform(request): if request.method == 'POST': basicForm = BasicForm(request.POST) if basicForm.is_valid(): name = basicForm.cleaned_data['name'] if BasicFormModel.objects.filter(name=name).exists(): favourite_color = basicForm.cleaned_data['favourite_color'] choices = basicForm.cleaned_data['choices'] context = { 'name': name, 'favourite_color': favourite_color, 'choices': choices } template = loader.get_template('nameexists.html') return HttpResponse(template.render(context, request)) else: favourite_color = basicForm.cleaned_data['favourite_color'] choices = basicForm.cleaned_data['choices'] print("cleanded choices="+choices) choices = dict(basicForm.fields['choices'].choices)[choices] print(choices) b = BasicFormModel(name=name, favourite_color=favourite_color, choices=choices) b.save() context = { 'name': name, 'favourite_color': favourite_color, 'choices': choices } template = loader.get_template('thankyou.html') return HttpResponse(template.render(context, request)) else: form = BasicForm() return render(request, 'responseform.html', {'form':form});
Django get_absolute_url on sitemap.xml getting NoReverMatch error
models.py def get_absolute_url(self): return reverse('abc', kwargs={'slug': self.slug}) urls.py from posts.views import xyz from posts.sitemaps import PostSitemap sitemaps = { 'posts': PostSitemap() } urlpatterns = patterns( url(r'^posts/(?P<slug>[\w-]+)/$',xyz, name='abc'), url(r'^sitemap\.xml$',sitemap, {'sitemaps': sitemaps}), ) sitemaps.py class PostSitemap(Sitemap): changefreq = 'daily' pirority = 0.5 def items(self): return Post.objects.all() I have not changed the default contib/sitemaps/templates/sitemap.xml and when I browse mysite/sitemap.xml it's throwing error: Reverse for 'abc' with arguments '()' and keyword arguments '{'slug': u'my-slug-goes-here'}' not found. 0 pattern(s) tried: []
class PostSitemap(Sitemap): changefreq = 'daily' pirority = 0.5 def items(self): return Post.objects.all() def location(self, item): return item.get_absolute_url()
Django View Throwing HttpResponseError
I am simply trying to map a view to a path in urls.py, but when I try to it throws this error: Registration didn't return an HttpResponse object urls.py urlpatterns = patterns('', (r'^Register/$', Registration), (r'^Newuser/$', ProcessRegistration), ) views.py def Registration(request): RegForm = RegistrationForm(request.POST or None) if request.method == 'POST': if RegForm.is_valid(): clearUserName = RegForm.cleaned_data['userNm'] clearPass = RegForm.cleaned_data['userPass'] RegForm.save() try: return HttpResponseRedirect('/Newuser/?userNm=' + clearUserName) except: raise ValidationError(('Invalid request'), code='300') ## [ TODO ]: add a custom error page here. else: RegForm = RegistrationForm() return render(request, 'VA/reuse/register.html', { 'RegForm': RegForm }) def ProcessRegistration(request): clearUserName = request.GET.get('userNm') return HttpResponse("Wee") When I visit /Register, it throws the above error. Any idea why its not working? It is returning a response of Wee
the validators=[] for userNm was messing it up within my models.py . I was up doing: class Client(models.Model): userNm = models.EmailField(verbose_name="Email",max_length=50,unique=True,validators=[RegexValidator('^\w{6,50}$','format: invalid username','Invalid Entry')]) userPass = models.CharField(verbose_name="Password", max_length=50) I changed the userNm declaration to: userNm = models.EmailField(verbose_name="Email",max_length=50,unique=True)