0

There is urls.py pattern.

    url(r'^notice/(?P<article>[0-9]\d+)/', web.views.notice),

Here is views.py

def notice(request, article):
    data = article
return render(request, "notice.html")

However, web brower shows 404 Error. If I remove add parameter, it is ok.

What I am wrong?

Intended result (Blog style, not get parameter) /notice/1, /notice/2, ...

3
  • What is article? Is it a digit from 0 to 9? Commented Jun 2, 2017 at 2:54
  • Hello Matt. It means digit Commented Jun 2, 2017 at 2:58
  • Here is example I tried. example.com/notice/1 Commented Jun 2, 2017 at 3:01

3 Answers 3

1

I think what is happening is that [0-9]\d+ is expecting at least a 2-digit number, one digit for the [0-9] and then one or more digits following that due to the \d+. I believe what you really want is just

url(r'^notice/(?P<article>\d+)$', 'web.views.notice')
Sign up to request clarification or add additional context in comments.

5 Comments

Still not solved. Django can't find webpage (404 Error)
Try adding apostrophes around 'web.views.notice' as in my edit.
I solved problems.url(r'^notice/(?P<article>\d+)/$ ', web.views.notice)
But the view is expecting something called article.
Thanks your cooperation sir.
0

I don't know why you use d???

url(r'^issue/(?P<issue_id>[0-9]+)$', views.issue, name='issue'),
url(r'^project/(?P<pk>.*)$', login_required(views.ProjectView.as_view()), name='project'),

Comments

0

Based on the question you asked, I am getting that you want to display the data on the template based on the parameter passed in the URL.Let me try to explain it step by step:

  1. First lets say you have the following url:

    url(r'^notice/(?P<article>\d+)$', views.notice,name="notice")

  2. Now lets define the view for fetching the data from the model, based on the parameter in the URL, i am assuming you are passing the PK in the URL:

    def notice(request, article):

    data = YourModelName.objects.get(id=article)

    //Passing back the result to the template

    context={"article":data}

    return render(request, "notice.html",context)

  3. Now in your template you can access the data as such:

    {{ article.field_name }}

Hope this helps you out!!!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.