django view called twice

  • Last Update :
  • Techknowledgy :

The url patterns are written in the following order (note that each has a unique name although it's tied to the same ads view):

urlpatterns = patterns('',
url(r'^buy_and_sell/$', ads,name='classified_listing'),
url(r'^buy_and_sell/barter/$', ads,name='barter_classified_listing'),
url(r'^buy_and_sell/barter/(?P<city>[\w.@+-]+)/$', ads,name='city_barter_classified_listing'),
   url(r'^buy_and_sell/(?P<city>[\w.@+-]+)/$', ads,name='city_classified_listing'),

The problem is that when I hit the url named classified_listing in the list above, the function ads gets called twice. I.e. here's what I see in my terminal:

[14 / Jul / 2017 14: 31: 08]
"GET /buy_and_sell/ HTTP/1.1"
200 53758
   [14 / Jul / 2017 14: 31: 08]
"GET /buy_and_sell/None/ HTTP/1.1"
200 32882

Suggestion : 2

In my case, the problem occurs only when CACHES is set to "real cache" like MemcachedCache or LocMemCache (default value if this variable is not set) etc.,Google Chrome sends a request when you type the url. So, when you hit enter, it sends another request. The problem you are having is probably because the time between typing the url and pressing enter is very short.,You could perhaps implement a time-based view like this to circumvent the problem.,I have run into the same problem...I printed all the request and checked logs of and found that render calls views two more times for css files

Try to set on your production server (Apache):

   'default': {
      'BACKEND': 'django.core.cache.backends.dummy.DummyCache',

And make sure you have configured SESSION_ENGINE:

SESSION_ENGINE = 'django.contrib.sessions.backends.db'

Suggestion : 3

Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site. ,Shiv is a Technical Architect. He is a bright Java developer and has worked on development of various SaaS applications using Grails, Spring and Hibernate framework.

<img src="" alt="User Image" width="500" height="500"> // Causes twice call to rendering action.

Suggestion : 4

Dec 2, 2021 , Start date Dec 2, 2021

#expects public_address, nonce and token
if user is currently signed in
def get_token(request):
public_address =["public_address"]
web3 = Web3Backend()
logger.debug('running authenticate from token endpoint')
user, token = web3.authenticate(request)
if token:
   return JsonResponse({
      'token': token
   return Response({
      'message': 'Missing token'
   }, status = 400)
import { fireEvent, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import Chatbot from "./Components/Chatbot";

test ("User says 'Hello!'", async () => {
    render(<Chatbot />);

    const inputField = screen.getByTestId("chatbot-input");
    const submitButton = screen.getByTestId("submit-button");

    fireEvent.change(inputField, { target: { value: "Hello!" } });;

    const messageComponent = screen.findByTestId("message");
Unable to find an element by: [data-testid="message"]

      <div data-testid="header">
      <div data-testid="messages"></div>
         <input value="" data-testid="chatbot-input" />
      <button data-testid="submit-button" type="submit">SUBMIT</button>
FROM / azure - functions / python: 4 - python3 .8 - core - tools # only a single line in the file to setup image which runs azure functions

Suggestion : 5

If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome., help? What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum About Us ,Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues ,Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.

        public async Task<httpresponsemessage> AddNewClient([FromBody]usp_GetClientDetails client)
                usp_GetClientDetails result = new usp_GetClientDetails();
                await Task.Run(() =>
                    result = IClientRepository.InsertClientDetails(client);
                return Request.CreateResponse(HttpStatusCode.OK, new { StatusCode = HttpStatusCode.OK, Status = "Success", Data = result });
            catch (Exception ex)
                return Request.CreateResponse(HttpStatusCode.NotFound, new { StatusCode = HttpStatusCode.InternalServerError, Status = "Failed", Data = ex.Message });

        public ActionResult AddClient(ClientAddModel objcltModel)
            var parameters = new usp_GetClientDetails
                LastName= objcltModel.LastName,
                EmailId= objcltModel.EmailId,
                PrimaryContactNo= objcltModel.PrimaryContactNo,
                SecondaryContactNo= objcltModel.SecondaryContactNo,
                AadharNo= objcltModel.AadharNo,
                PanNo= objcltModel.PanNo,
                Pincode= objcltModel.Pincode,
                City= objcltModel.City,
                Area1= objcltModel.Area1,
                Area2= objcltModel.Area2,
                FloorNo= Convert.ToInt32(objcltModel.FloorNo),
                FlatNo= objcltModel.FlatNo,
                BuildingName= objcltModel.BuildingName,

            var result = WebAPIGeneric.GetAPIResponse(WebAPIMethods.SaveClientDetails, parameters, Method.POST, null);
            if(result !=null)
                    ViewBag.Message = "Client Added Successfully";//JsonConvert.DeserializeObject<usp_getclientdetails>(result.Data.ToString()).Message;
            ViewBag.Userlst = getUserList() == null ? new SelectList(string.Empty) : new SelectList(getUserList().ToList(), "UserId", "FullName");
            return View("Index");
public static ResponseModel GetAPIResponse(string Url, object data, Method method,Hashtable htable)
            var client = new RestClient(Common.baseUrl);
            var request = new RestRequest(Url, method);
            if(data==null && htable !=null)
                foreach(DictionaryEntry entry in htable)
                //request.AddParameter("application/json", JsonConvert.SerializeObject(htable), ParameterType.QueryString);
            var x = client.Execute(request);
            return JsonConvert.DeserializeObject<responsemodel>(client.Execute(request).Content);
var x = client.Execute(request); // <-- first call return JsonConvert.DeserializeObject<ResponseModel>(client.Execute(request).Content); // <-- Second one here
var x = client.Execute(request);
return JsonConvert.DeserializeObject<ResponseModel>(x.Content); // Use the x here